在我看來,Maven依賴插件在計算依賴列表時行爲異常。maven依賴項插件忽略依賴項版本?
假定這3個項目:
BASE1:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>mygroup</groupId>
<artifactId>base1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</project>
BASE2:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>mygroup</groupId>
<artifactId>base2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</project>
組合:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>mygroup</groupId>
<artifactId>combined</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>mygroup</groupId>
<artifactId>base1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>mygroup</groupId>
<artifactId>base2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
兩者,BASE1和BASE2取決於公地琅,但每個人都不一樣版本! 組合取決於base1和base2。
在聯合調用mvn dependency:list
時,我期望在版本2.3和2.6中看到base1,base2和commons-lang,因爲兩者都被使用。 但是實際的輸出是:
[INFO] The following files have been resolved:
[INFO] commons-lang:commons-lang:jar:2.3:compile
[INFO] mygroup:base1:jar:1.0-SNAPSHOT:compile
[INFO] mygroup:base2:jar:1.0-SNAPSHOT:compile
它甚至沒有使用常見的琅最高版本號,但只是一個首先發現。
我該如何避免這種情況?我需要所有的依賴關係。
最適合你的是改變需要依賴commons-lang:2.3的代碼。對不起...... – otonglet
@otonglet如果base1和base2是第三方模塊,我不能這樣做。 – radlan
@radlan你有沒有把mvn依賴:list與['mvn dependency:tree'](https://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html)混淆? – nullpointer