【发布时间】:2016-06-22 14:58:49
【问题描述】:
我们有多个模块项目设置,对不同的模块版本有很多依赖。
ParentModule_16.3.0.1.0-
----ChildModule1_16.3.0.1.0
----ChildModule2_16.3.0.1.0
----ChildModule3_16.3.0.1.0
之前所有版本的每个模块都在 pom.xml 中硬编码。后来我们决定从属性文件中获取这些版本。所以我按照下面的链接,它工作得很好-
Maven: set property in pom.xml from properties file
现在我们有一个需要更新版本的场景 childmodule2_16.3.0.1.0 到 childModule2_16.6.0.0.0 和 parentModule_16.3.0.1.0 到 parentModule_16.6.0.0.0 其余部分保持不变。
现在我们面临的问题是,当我们使用父级的 pom 进行完整构建时,由于旧版本(16.3.0.1.0),它不会选择某些模块的 jar。
我读过一些博客,上面说 maven 总是选择最新版本。因此旧的 jars 没有被选中。有些人说你总是必须指定父版本。幸运的是,在大多数情况下,它作为模块的版本被继承。此外,Maven Release Plugin 会自动更改此父级的版本声明。
请帮助我理解这一点。有没有办法解决这个问题?提前致谢。
下面是我的父 pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>parent</artifactId>
<version>${parent-version}</version>
<packaging>pom</packaging>
<modules>
<module>chiled1</module>
<module>child2</module>
</modules>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>version.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<parallel>methods</parallel>
<threadCount>10</threadCount>
</configuration>
</plugin>
<!-- Make assembly -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<descriptor>${project.basedir}/assembly.xml</descriptor>
<outputDirectory>${project.basedir}/dist</outputDirectory>
</configuration>
<executions>
<execution>
<id>create-archive</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
child2 pom.xml
<groupId>com.myproject.child1</groupId>
<artifactId>child2</artifactId>
<version>${child2-version}</version>
<build>
<finalName>${project.artifactId}-${version}</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>../version.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
version.properties
之前 -
现在——
【问题讨论】:
-
如果你有一个多模块构建,基本思想是在所有模块中为模块本身提供相同的版本。除此之外,如果您使用 maven 发布插件,也会更新所有子模块版本..否则会出现问题...
-
但这里的想法是更新在当前版本中修改的那些模块的版本。我们不想更新未更改或未触及模块的版本。
-
如果考虑这种方式,您需要在模块的不同版本之间进行测试,如果您获得更多不同版本,则需要更多测试......
标签: java maven build-process versioning multi-module