I am working on a Java project and I'm using commitizen to enforce semantic version in CI, when I run the command cz bump and cz changelog update the .cz.yaml and changelog files with the new version but is not updating the version in pom.xml. Is there a functionality in Commitizen to update this file too?
Additionally: the application is currently being built by Maven
As I mentioned in my comment above, there is a way to solve this problem and after some testing I'd like to provide you a simple solution now.
I assume you have
.cz.tomlfile in place and already configured and use maven as build system for your Java project.First you should add a
scriptsfolder to the maven root. And put 2 shell scripts in there. The first isprepare_java_version.shand the content is:The second file is
commit_java_version.shand in that file you put the content:Now you have to edit the
.cz.tomlfile and append these two sections:And now, you are ready to go.
Explanation: Commitizen calls the
pre_bump_hooksjust before the tag is created, and the shell script modifies thepom.xmlto the given version. The Version used in the shell script is an environment variable provided by commitizen.After the commit and the tag are created the
post_bump_hooksare called and this shell script clean up the maven repo again. The version backup file is removed for example.Hint: If there is a problem, and you need to revert the version change in the pom.xml just call
mvn versions:revertand you have the old version. But this only works before the commit is called.