我有一个Maven结构,如:
- Parent
- Child 1
- Child 2我已经定义了Parent <version>1.0-SNAPSHOT</version>,并且没有版本的Child 1和Child 2,这样两个子版本都将自动继承Parent版本。
问题是,我需要将Child 1作为依赖项引用到Child 2,唯一的方法是传递Child 1版本,例如:
<dependency>
<groupId>com.myapp</groupId>
<artifactId>child-1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>我想避免这种情况,因为两个子类无论如何都会继承Parent版本,但我不能将Child 1包括为:
<dependency>
<groupId>com.myapp</groupId>
<artifactId>child-1</artifactId>
</dependency>是否有一种方法可以避免引用Child 1 Child 2 verion on Child 2 POM??
自动实现这一点的可能性要小得多。
发布于 2018-12-06 20:23:26
当然,你能做到的。
亲本pom.xml
<groupId>com.acme</groupId>
<artifactId>root</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>child-1</module>
<module>child-2</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.acme</groupId>
<artifactId>child-1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.acme</groupId>
<artifactId>child-2</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<dependencyManagement>然后只引用没有版本的兄弟姐妹:
儿童1 pom.xml
<parent>
<groupId>com.acme</groupId>
<artifactId>root</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>child-1</artifactId>
<name>Child 1</name>
<dependencies>
<dependency>
<groupId>com.acme</groupId>
<artifactId>child-2</artifactId>
</dependency>
</dependencies>儿童2 pom.xml
<parent>
<groupId>com.acme</groupId>
<artifactId>root</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>child-2</artifactId>
<name>Child 2</name>
<dependencies>
<dependency>
<groupId>com.acme</groupId>
<artifactId>child-1</artifactId>
</dependency>
</dependencies>子版本中的显式父版本并不是一个问题,因为mvn versions:set和Maven发布插件都可以处理这个问题。
https://stackoverflow.com/questions/53643783
复制相似问题