在以下多项目案例中,版本控制和发布管理的最佳实践是什么?
项目结构
- 全局母公司
- 父项目(版本:1.0-SNAPSHOT)
- 子项目 1(与父项目相同)
- 子项目 2(与父项目相同)
- 子项目 3(与父项目相同)
- 子项目 4(与父项目相同)
- …
- 父项目(版本:1.0-SNAPSHOT)
我只想为父项目和所有子项目设置一次版本,因为项目的每一部分都必须具有相同的版本。
另外我想要的是,用 continuum/maven 发布项目。
当前的“坏”解决方案:
通常,一个简单的方法应该是在父 pom 中设置版本,并在每个 child 中说“父版本的最后一个版本”,但这不适用于 maven <3.1(参见此处)[http://jira.codehaus.org/浏览/MNG-624] 现在我在每个子项目中设置父项目的版本,并且对于每个版本我必须更改所有子项目和父项目的版本。
例子:
父级
<groupId>com.test</groupId>
<artifactId>com.test.buildDefinition</artifactId>
<version>1.0-SNAPSHOT</version>
child
<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 发布我的项目,我使用以下顺序来发布它:
- 父项目
- 子项目 1
- 子项目 2
- …
但这行不通,因为在更改父版本后,子版本在父版本中不再有 SNAPSHOT 版本,我认为必须有更好的方法来发布具有连续性的多项目。
最佳答案
如果您在 <dependencyManagement/>
中添加您的子模块tag 我很确定你不会有那个问题。
父级
<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>
child 1
<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
与亲子之间的继承没有任何关系。它解决了子模块之间依赖版本的任何问题。它在发布期间有效。
关于java - 最佳实践 : Versioning and releases in multiprojects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12038984/