如何让Maven Release Plugin跳过Git子模块common的发布?
解决Maven多模块发布时忽略Git子模块的方案
方案1:在父POM中配置Release插件排除指定模块
在父项目的pom.xml中,给maven-release-plugin添加配置,指定要排除的模块ID:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>3.0.1</version> <!-- 使用最新稳定版本 --> <configuration> <!-- 排除common模块,不参与发布流程 --> <excludeModuleIds>common</excludeModuleIds> <!-- 可选:确保不提交common目录下的任何变更 --> <checkModificationExcludes> <checkModificationExclude>common/**</checkModificationExclude> </checkModificationExcludes> </configuration> </plugin> </plugins> </build>
该配置会让release插件在prepare和perform阶段自动跳过common模块,不会修改其版本号,也不会提交相关pom变更。
方案2:给common模块单独配置跳过发布
在common模块的pom.xml中,配置maven-release-plugin直接跳过自身的发布操作:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin> </plugins> </build>
此配置会让发布流程完全忽略该模块,保持其版本和pom文件不变。
方案3:通过Profile控制发布时的模块范围
在父POM中定义发布专用Profile,激活后仅包含需要发布的模块:
<profiles> <profile> <id>release</id> <modules> <module>first</module> <module>second</module> </modules> </profile> </profiles>
在GitLab发布流程中执行命令时激活该Profile:mvn release:prepare release:perform -Prelease,即可仅发布指定模块。
注意事项
- 确保
common模块使用稳定的正式版本(非SNAPSHOT),避免影响其他模块的发布稳定性。 - 本地测试时可执行
mvn release:prepare -DdryRun=true干跑验证,确认common模块未被修改。
内容的提问来源于stack exchange,提问作者smacz76
相关产品推荐
相关产品推荐

