This simple module demos how to use Conventional Commits, Git Hooks to enforce Conventional Commits and Semantic Versioning in a Java project built with Maven.
This is the companion project to the article Supercharge your Java Projects with Conventional Commits, Semantic Versioning and Semantic Releases.
Also, if you want to see what the code looks like after we've added the changelog etc, check the release branch.
Make sure you have setup your local Git Hooks:
git config core.hooksPath .githooksThis will make sure your commit messages follow the Conventional Commits Specification.
Here's some handly commands:
| Command | Usage |
|---|---|
./mvnw -B verify |
Run the tests. |
./mvnw -B package |
Run the builds. |
This project uses standard-release to update the version in the pom.xml file from the changes in the history and to create the CHANGELOG.md file.
To setup semantic versioning and create the baseline changelog, run:
npx dwmkerr/standard-version --first-release --packageFiles pom.xml --bumpFiles pom.xmlNow any time you want to cut a new release, run:
npx dwmkerr/standard-version --packageFiles pom.xml --bumpFiles pom.xmlThis will:
- Update the
CHANGELOG.md - Update the version number based on the commit history
- Create a git tag with the new version number
Finally, just push the tag to trigger a deployment of the new version:
git push --follow-tagsAs per the spec: https://semver.org/spec/v2.0.0.html#doesnt-this-discourage-rapid-development-and-fast-iteration please note that Major Version 0 (i.e. 0.x.y) is for about rapid development. Major changes do not increase the major version number - only the minor version number. This is in alignment with the semver spec, that reserves major version zero for rapid changes that are expected to break the API.