在以下情况下使用多项目进行版本控制和发布管理的最佳做法是什么?
我只想为父项目和所有子项目设置一次版本,因为项目的每个部分都必须具有相同的版本。
我想要的是,用continuum / maven发布项目。
Normaly一个简单的方法应该是在父pom中设置版本并在每个孩子中说“父母的最后一个版本”,但这不适用于maven< 3.1(见这里)[http://jira.codehaus。组织/浏览/ MNG-624] 现在我在每个子项目中设置父项目的版本,并且对于每个版本,我必须更改所有子项和父项的版本。
示例:
父
<groupId>com.test</groupId>
<artifactId>com.test.buildDefinition</artifactId>
<version>1.0-SNAPSHOT</version>
儿童
<parent>
<groupId>com.test</groupId>
<artifactId>com.test.buildDefinition</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.test</groupId>
<artifactId>com.test.project</artifactId>
<version>${parent.version}</version>
如果我想现在使用Continuum发布我的项目,请使用以下命令将其发布:
但是这不起作用,因为在更改父版本之后,孩子们在父母中不再有SNAPSHOT版本,我认为必须有更好的方法来发布连续体的多项目。
答案 0 :(得分:2)
如果您在<dependencyManagement/>
标记中添加子模块,我确信您不会遇到此问题。
<强>父强>
<groupId>com.test</groupId>
<artifactId>com.test.buildDefinition</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>child1</module>
<module>child2</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>com.test.child1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.test</groupId>
<artifactId>com.test.child2</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<强> Child1 强>
<parent>
<groupId>com.test</groupId>
<artifactId>com.test.buildDefinition</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<!-- groupId and version can be skipped since it will be inherited from parent -->
<artifactId>com.test.child1</artifactId>
Child2(取决于Child1)
<parent>
<groupId>com.test</groupId>
<artifactId>com.test.buildDefinition</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<!-- groupId and version can be skipped since it will be inherited from parent -->
<artifactId>com.test.child2</artifactId>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>com.test.child1</artifactId>
</dependency>
</dependencies>
如果您尝试使用dependencyManagement时,模块之间的依赖关系将永远不必定义任何版本,因为它们是在父pom中定义的。
通过这种方法发布多模块项目我从来没有遇到任何问题。
修改强>
要明确:dependencyManagement
与父子之间的继承没有任何关系。它解决了子模块之间依赖关系版本的任何问题。它在发布期间有效。
答案 1 :(得分:1)
您应该在单个版本控制层次结构下为同时版本相同的模块创建一个多模块结构。 Continuum允许您将它们作为单个作业或每个模块的多个作业添加到组中,并且释放机制将从父项触发并自动为您解析版本。
顺便说一句,您可以删除<version>${parent.version}</version>
和相同的groupId,因为它们将从父级继承。
如果全局父级单独发布,则应将其拆分为单独的模块,而不是使其成为同一多模块结构的一部分。您可以在此布局中找到示例项目:https://github.com/brettporter/centrepoint
答案 2 :(得分:0)
如果您希望所有版本号保持同步,则可以使用Maven版本插件的autoVersionSubmodules标志。将此值设置为true将允许您在顶级项目级别执行发布,并释放所有子模块与父项相同的版本。
这可以在运行mvn -DautoVersionSubmodules release:prepare
时在命令行中指定,也可以在POM文件中指定,如下所示:
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</plugin>
我没有使用Continuum,但我相信它使用了封面下的Maven发布插件?一些谷歌搜索表明这可能会起作用(基于一些关于Continuum接口如何处理这种情况的“很好的”错误)。