有没有一种方法可以使用 git commit hook 在 git commit 上自动更新 pom.xml 文件?
我想做的是,我想用基于分支名称的新版本替换旧版本的所有实例。
例如。
如果我从 master checkout ,我可能会在我的 pom.xml 中找到
<dependancy>
<groupId>com.mycompany</groupId>
<artifactId>my_component</artifactId>
<version>master-SNAPSHOT</version>
</dependancy>
或
<groupId>com.mycompany.project</groupId>
<artifactId>mainProject</artifactId>
<version>master-SNAPSHOT</version>
<name>mainProject</name>
我想做的是确保提交新分支的每个人都在 pom.xml 中反射(reflect)了该新分支。因此,如果我基于名为“myNewBranch”的 master 创建一个新分支,我希望 pom.xml 自动更新为以下内容:
<dependancy>
<groupId>com.mycompany</groupId>
<artifactId>my_component</artifactId>
<version>myNewBranch-SNAPSHOT</version>
</dependancy>
或
<groupId>com.mycompany.project</groupId>
<artifactId>mainProject</artifactId>
<version>myNewBranch-SNAPSHOT</version>
<name>mainProject</name>
最佳答案
您正在寻找核心 Maven 或 Maven SCM plugin 未提供的“开箱即用”的东西。 .
您必须编写一个在提交后运行的 shell 脚本,该脚本以编程方式获取(或创建)分支名称,符合 How to programmatically determine the current checked out Git branch然后调用 mvn versions:set
您还可以做一些事情,比如制作自定义 Maven 插件或 maven-ant-run执行来做到这一点,但我认为脚本方法对您来说是阻力最小的途径。
关于git - 如何确保提交新分支的每个人都在 pom.xml 中反射(reflect)了更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17172037/