Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transitive dependencies not resolved when dependency version defined in parents dependencyManagement

I've got a multi-module project with layout as below:

pom.xml
projA
  trunk
    pom.xml
    projA1
      pom.xml
    projA2
      pom.xml

In the parent's pom I've defined dependencyManagement and properties:

<properties>
  <javaee-api.version>6.0</javaee-api.version>
  <log4j.version>1.2.11</log4j.version>
</properties>
...
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>  
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
    </dependency>
    <dependency>
      <groupId>javax</groupId>  
      <artifactId>javaee-api</artifactId>
      <version>${javaee-api.version}</version>
    </dependency>
  </dependencies>
</dependencyManagement>

pom.xml for projA2 contains:

<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
</dependency>

pom.xml for projA1 contains:

<dependency>
  <groupId>${project.groupId}</groupId>
  <artifactId>projA2</artifactId>
  <version>${project.version}</version>
</dependency>

In projA1 I'm using log4j but the dependency is transitive (from projA2).

Now when I run mvn dependency:tree -X I get:

[WARNING] Invalid POM for mypackage:projA2:jar:1.0, transitive dependencies (if any) will not be available, enable debug logging for more details: Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for javax:javaee-api:jar is missing. @ line 37, column 15
[ERROR] 'dependencies.dependency.version' for log4j:log4j:jar is missing. @ line 56, column 15

but just below this lines I get:

[DEBUG]   testArtifact: artifact=log4j:log4j:jar:1.2.11:compile
[DEBUG]   includeArtifact: artifact=log4j:log4j:jar:1.2.11:compile
[DEBUG]   startProcessChildren: artifact=log4j:log4j:jar:1.2.11:compile
[DEBUG]   endProcessChildren: artifact=log4j:log4j:jar:1.2.11:compile
[DEBUG]   testArtifact: artifact=javax:javaee-api:jar:6.0:provided
[DEBUG]   includeArtifact: artifact=javax:javaee-api:jar:6.0:provided
[DEBUG]   startProcessChildren: artifact=javax:javaee-api:jar:6.0:provided
[DEBUG]   endProcessChildren: artifact=javax:javaee-api:jar:6.0:provided

The only solution is to specify log4j version (<version>${project.version}</version>) in projA2 pom.xml.

Question: what am I doing wrong :-(? I don't want to specify versions that are already defined in parent's dependencyManagement section.

like image 492
Arek Avatar asked Feb 08 '13 19:02

Arek


2 Answers

I has faced same problem. In my case if forgot update parent POM in local repository. Try to do

mvn install

for parent module.

like image 91
Andrey Lyubimov Avatar answered Oct 24 '22 10:10

Andrey Lyubimov


Had a similar issue. Removing (manually) all the projects involved from the local repository and run "mvn clean install" later worked for me.

like image 23
alexgrimaldi Avatar answered Oct 24 '22 10:10

alexgrimaldi