Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add maven provider #962

rshmhrj started this conversation in Ideas
Jan 17, 2024 · 1 comments · 1 reply
Discussion options

At work, I am currently trying to set up commitizen on a handful of Java libraries and am not sure the best option to choose on cz init regarding the source of the version.

  • Maybe the commitizen config option would be fine, since I'm already adding the toml
  • npm is out of the question since it seems unnecessary to have to add a package.json to a Java project
  • Also, eventually, I want to be able to have cz run in our Azure DevOps pipeline whenever we are creating a release from develop to master

This led me to consider extending the selections to include Maven's pom.xml and be able to both get AND set the project.version

This seems possible by invoking maven directly from the command line via a subprocess in python:

import subprocess
def run_cmd(command):
 return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).stdout.read()
version_cmd='mvn help:evaluate -Dexpression=project.version -q -DforceStdout'
version = run_cmd(version_cmd)
print(version.decode())
image

If this looks like an okay starting point, I can create a PR with a first stab at the commitizen/providers/maven_provider.py file.

Not sure what else will need to update yet though, so any guidance would be welcome!

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

Hi! Thanks for this info, we recommend creating a new package for different version handlers.

Here's an example on how to build a custom version provider:
https://commitizen-tools.github.io/commitizen/config/#custom-version-provider

You must be logged in to vote
1 reply
Comment options

Hi @woile , thanks for the reference!

Few questions for you:

  • Would this wire up Maven/mvn to be a choice on cz init ?
  • Would your suggestion be the same or similar if we also wanted to add a new version scheme (basically SemVer plus a qualifier, like 3.2.1-SNAPSHOT)?

I looked into the code last night and was able to put together PR #963 just adding mvn as an option on cz init.
I'm still looking into adding a MavenVer class in version_schemes to handle the various java qualifiers.

I have been using this as a reference: https://octopus.com/blog/maven-versioning-explained

By the way, just wanted to say how lovely the code base and tooling setup is. This is my first time using most of these tools and it has been a great experience so far!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /