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.toml
file in place and already configured and use maven as build system for your Java project.
First you should add a scripts
folder to the maven root. And put 2 shell scripts in there. The first is prepare_java_version.sh
and the content is:
#!/bin/bash
mvn versions:set -DnewVersion=$CZ_PRE_NEW_VERSION
The second file is commit_java_version.sh
and in that file you put the content:
#!/bin/bash
mvn versions:commit
Now you have to edit the .cz.toml
file and append these two sections:
pre_bump_hooks = [
"scripts/prepare_java_version.sh"
]
post_bump_hooks = [
"scripts/commit_java_version.sh"
]
And now, you are ready to go.
Explanation:
Commitizen calls the pre_bump_hooks
just before the tag is created, and the shell script modifies the pom.xml
to 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_hooks
are 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:revert
and you have the old version. But this only works before the commit is called.