How do I bump the version of a Maven project?

Commands to run at the terminal are highlighted like this.

The following commands assume that your GitHub remote is called "github". If not (it is often called "origin" if no --origin=customNameHere was passed to git clone), you can rename it, like so: git remote rename origin github. Or you can just substitute whatever your remote is called for "github".

  1. Make sure your local copy of the project is up-to-date. Pull the latest commits from GitHub to your local dev (or potentially some other, if making a hotfix) branch: git checkout dev && git pull github dev.
  2. Create a new branch for purposes of bumping the version. I usually call it "dev_version_bump": git checkout -B dev_version_bump (the capital -B indicates that replacing an existing branch with that name is okay).
  3. Edit the <version> in pom.xml. Set it to the next even number. e.g. if the version is currently "0.0.1337-SNAPSHOT", use "0.0.1338" (unless you have a reason to use a different numbering scheme, e.g. if we are using semantic versioning).
  4. Commit that with the message "Bump version to 0.0.1338" (or whatever).
  5. Note the commit hash. git rev-parse HEAD will print it out. We'll use this later, when making the tag. For this example, let's say it prints "evenversioncommithash123456789abcdef0000".
  6. Again, edit the <version> in pom.xml. Set it to the next odd number + "-SNAPSHOT". e.g. "0.0.1339-SNAPSHOT".
  7. Commit that with the message "Bump version to 0.0.1339-SNAPSHOT" (or whatever).
  8. Push the branch to github: git push github dev_version_bump:dev_version_bump.
  9. Go to GitHub, open a PR to have that merged to dev. Don't click merge! GitHub always creates merge commits, but in this case we want a fast-forward, so we'll push that from the command-line in the next step.
  10. Back at the command-line, run git push github dev_version_bump:dev. Repeat until someone approves your PR, at which point this should succeed.
  11. Tag the commit: git tag 0.0.1338 evenversioncommithash123456789abcdef0000
  12. Push the tag to GitHub: git push github 0.0.1338.
  13. Go to GitHub, go to the 'Actions' tab for the project, pick 'Build and Deploy' from the list on the left, click the 'Run workflow ▾' dropdown, find the tag you just created, and then click the 'Run workflow' button.
  14. After this completes, you can reference the new version from other projects' pom.xml and Maven will automatically download them as needed.

Feel free to automate any of the above.

Notes: