Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make sure that everyone who commits a new branch has the changes reflected in the pom.xml?

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>
like image 553
Avik Avatar asked Oct 21 '22 07:10

Avik


1 Answers

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.

like image 136
noahlz Avatar answered Nov 01 '22 13:11

noahlz