Is there a way I can automatically update a pom.xml file on a git commit using a git commit hook?
What I want to do, is I want to replace all instances of the old version, with the new version based on the branch name.
For example.
If I check out from master I might find in my pom.xml
<dependancy>
<groupId>com.mycompany</groupId>
<artifactId>my_component</artifactId>
<version>master-SNAPSHOT</version>
</dependancy>
or
<groupId>com.mycompany.project</groupId>
<artifactId>mainProject</artifactId>
<version>master-SNAPSHOT</version>
<name>mainProject</name>
What I would like to do, is to make sure that everyone who commits a new branch, has that new branch reflected in the pom.xml. So if I create a new branch based on master named "myNewBranch", I would like the pom.xml to be automatically updated to the following:
<dependancy>
<groupId>com.mycompany</groupId>
<artifactId>my_component</artifactId>
<version>myNewBranch-SNAPSHOT</version>
</dependancy>
or
<groupId>com.mycompany.project</groupId>
<artifactId>mainProject</artifactId>
<version>myNewBranch-SNAPSHOT</version>
<name>mainProject</name>
You are looking to do something that is not provided "out of the box" by core Maven or the Maven SCM plugin.
You'll have to write a shell script that runs on post-commit that programmatically obtains (or creates) the branch name as per How to programmatically determine the current checked out Git branch and then calls mvn versions:set
You could also do something like make a custom Maven plugin or maven-ant-run execution to do this, but I think the script approach will be the path of least resistance for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With