How do you use the versions-maven-plugin to manage dependency and project versions, and what does versions:set vs versions:use-latest-versions do?
answer
- set = project's own version
- use-latest-versions = bump deps
- use-latest-releases avoids SNAPSHOTs
- display-* = report only
- versionsBackup + commit/revert
basics
~10 sversions-maven-plugin edits POM versions for you. versions:set changes the project's own version (across a multi-module build); versions:use-latest-versions bumps your declared dependencies to their newest available versions. It writes pom.xml.versionsBackup so you can revert.
solid answer
~40 sThe `versions-maven-plugin` is a Swiss-army knife for editing versions without hand-editing XML. `versions:set -DnewVersion=2.0.0` rewrites the current project's `<version>` and propagates it consistently to child modules and parent references in a reactor build. `versions:use-latest-versions` scans your `<dependencies>` and updates each to the newest available release in your repositories (variants exist: `use-next-versions`, `use-latest-releases` to avoid SNAPSHOTs, and `use-next-snapshots`). Reporting goals like `versions:display-dependency-updates` and `versions:display-plugin-updates` just list what could be upgraded without changing anything. By default it writes `pom.xml.versionsBackup`; run `versions:commit` to accept or `versions:revert` to undo. Useful filters include `-DallowSnapshots`, inclusion/exclusion patterns, and `-DprocessParent`. It's commonly used in CI scripts for automated dependency-bump PRs.
code
bash · 6 lines# Bump the project version
mvn versions:set -DnewVersion=2.0.0 && mvn versions:commit
# Upgrade dependencies to newest releases (no SNAPSHOTs), then report plugin updates
mvn versions:use-latest-releases
mvn versions:display-plugin-updatesgo deeper
Knows the plugin can edit versions instead of hand-editing pom.xml.
Distinguishes set vs use-latest-* goals, uses display-* reports, and the backup/commit/revert cycle.
Scopes upgrades with includes/excludes, integrates it into automated bump pipelines, and chooses release vs latest semantics deliberately.
Compares it with Renovate/Dependabot, defines the org's automated-upgrade and version-source-of-truth strategy.
## What it solves Manually editing versions across a multi-module project is tedious and error-prone (parent + children + dependencyManagement). The `versions-maven-plugin` automates it. ## Setting the project's own version ```bash mvn versions:set -DnewVersion=2.0.0 mvn versions:commit # accept (delete backups) -- or versions:revert ``` `versions:set` updates `<version>` in the current POM and rewrites parent references in child modules so the reactor stays consistent. This is the modern, lighter-weight alternative to the release plugin's version bumping. ## Updating dependency versions - `versions:use-latest-versions` — bump declared dependencies to the newest available (may include SNAPSHOTs only with `-DallowSnapshots=true`). - `versions:use-latest-releases` — newest **release** only. - `versions:use-next-versions` — step to the next available, not the latest. - `versions:update-properties` — when versions are held in `<properties>`, update those instead. ## Report-only goals (no edits) - `versions:display-dependency-updates` - `versions:display-plugin-updates` - `versions:display-property-updates` These print available upgrades — ideal in CI dashboards. ## Backups and safety Most mutating goals write `pom.xml.versionsBackup`. Then: - `versions:commit` — keep changes, remove backups. - `versions:revert` — restore the original POMs. ## Common flags - `-DprocessParent=true` to also bump the parent. - `-Dincludes=com.acme:*` / `-Dexcludes=...` to scope. - `-DgenerateBackupPoms=false` to skip backups in CI. ## When to reach for it - Automated dependency-update PRs (alternative/complement to Dependabot/Renovate). - Cutting versions in CI-friendly or scripted release flows without the full release plugin.
- How do you undo a versions:set you ran by mistake?Run versions:revert (restores from pom.xml.versionsBackup). Run versions:commit instead to make it permanent and delete the backups.
- How do you avoid pulling SNAPSHOT versions when upgrading?Use versions:use-latest-releases (or keep -DallowSnapshots=false, the default), which restricts upgrades to release versions only.
saying these in an interview costs you the question
- Confusing versions:set (own version) with use-latest-versions (dependency versions)
- Forgetting it can pull SNAPSHOTs unless restricted
- Not knowing about the backup/commit/revert safety net
- Assuming display-* goals modify the POM