Understand versions maven plugin basics with examples
versions-maven-plugin basics
Versions Maven Plugin is a plugin in the maven project used to update the versions of the application/artifact of a project.
Each artifact is a single module that has a dependency on other artifacts. Always Latest versions are stable with fixing bugs. This has advantages to checking the latest versions of dependencies as well as parent dependencies.
Keeping and managing this version is a tedious task for a developer. This plugin automates this managing version of dependencies in an application.
This generates a report of a project which contains all dependencies that are not using the latest version.
This will be very helpful during the release management of your project.
There are different goals available to report the following things.
- Checking the plugin’s latest versions
- Checking artifact dependencies versions update
- Update the artifact and dependencies version with the new version
- Update property versions to the latest.
- Checking parent dependency with the latest versions
- Checking snapshot version and update with release versions
- Update the next snapshot and release versions.
Adding version plugin to pom.xml
In artifact pom.xml, add this plugin in the plugins section as below. you need to provide groupid,artifactId, and version of this plugin. This is the way of using the version plugin.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>${maven.versions.plugin}</version>
</plugin>
</plugins>
</build>
Check the Dependency version of the maven project
In this demo artifact, JUnit has a dependency on version 3.8.1. Using this version plugin to check dependency version update pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cloudhadoop</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>app</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.versions.plugin>2.5</maven.versions.plugin>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>${maven.versions.plugin}</version>
</plugin>
</plugins>
</build>
</project>
the below is a maven command which runs in the project root directory
mvn versions:display-dependency-updates
This checks update from remote repository from central and displays them with old and new versions
[INFO] artifact junit:junit: checking for updates from central
[INFO] The following dependencies in Dependencies have newer versions:
[INFO] junit:junit ............................................ 3.8.1 -> 4.12
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
display-plugin-updates goal
This goal checks the latest versions of the plugins and their dependencies and displays the report to the console. Here is a sample output console log
[INFO] Require Maven 3.0 to use the following plugin updates:
[INFO] maven-clean-plugin ............................................ 3.1.0
[INFO] maven-compiler-plugin ......................................... 3.8.0
[INFO] maven-jar-plugin .............................................. 3.1.0
[INFO] maven-resources-plugin ........................................ 3.1.0
[INFO] org.codehaus.mojo:versions-maven-plugin ......................... 2.5
versions:display-property-updates goal
This goal reports whether version properties need to update to the latest version or not
[INFO] --- versions-maven-plugin:2.5:display-property-updates (default-cli) @ demo ---
[INFO] Major version changes allowed
[INFO]
[INFO] The following version properties are referencing the newest available version:
[INFO] ${maven.versions.plugin} ........................................ 2.5
[INFO] All version properties are referencing the newest version available.
[INFO]
[INFO] ------------------------------------------------------------------------
versions:set goal
This goal is to update the artifact version to the new version. You need to enter via command line which will be updated in pom.xml with new version information
b:\maven-release-plugin>mvn versions:set
INFO] Scanning for projects...
INFO]
INFO] ------------------------------------------------------------------------
INFO] Building app 1.0-SNAPSHOT
INFO] ------------------------------------------------------------------------
INFO]
INFO] --- versions-maven-plugin:2.5:set (default-cli) @ demo ---
nter the new version to set 1.0-SNAPSHOT: : 1.0.1
INFO] Searching for local aggregator root...
INFO] Local aggregation root: B:\maven-release-plugin
INFO] Processing change of com.cloudhadoop:demo:1.0-SNAPSHOT -> 1.0.1
INFO] Processing com.cloudhadoop:demo
INFO] Updating project com.cloudhadoop:demo
INFO] from version 1.0-SNAPSHOT to 1.0.1
INFO]
INFO] ------------------------------------------------------------------------
INFO] BUILD SUCCESS
versions:use-latest-versions goal
this goal checked the dependencies of an artifact with the central repository and replaces it with the latest versions.
Goals to modify pom.xml
Here are some goals available to modify the pom.xml file of your project.
mvn versions: revert
: this reverts the changes done to pom.xml from the git/svn repository
mvn versions:commit
: this commits the changes modified to pom.xml to a git repository
mvn versions:update-parent
:- This goal updates the parent pom version with the new version.
That’s all about the version maven plugin. Please share/comment on Facebook/Twitter for any questions.