我得與佈局下方的多模塊項目:傳遞依賴沒有解決時,在父母的依賴定義版本dependencyManagement
pom.xml
projA
trunk
pom.xml
projA1
pom.xml
projA2
pom.xml
在父母的POM我定義dependencyManagement
和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爲projA2包含:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
pom.xml中爲projA1包含:
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>projA2</artifactId>
<version>${project.version}</version>
</dependency>
在projA1我使用log4j的,但依賴是傳遞的(從projA2)。
現在,當我運行mvn dependency:tree -X
我得到:
[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
只是低於此線,我得到:
[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
唯一的解決辦法是在projA2 pom.xml中指定的log4j版本(<version>${project.version}</version>
) 。
問:?什麼我做錯了:-(我不想以指定在父母的dependencyManagement
部分已定義的版本
謝謝你的回答!我不想把這個依賴添加到projA中的所有項目中,還有兩個項目,所以你的解決方案將會沒有解決我的問題。 – Arek 2013-02-16 11:07:10