Maven: Managing Versions
How do you get the right version for dependencies, plugins, etc.
In a Maven pom.xml
, the author specifies dependencies such as:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
And plugins such as:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<reportOutputDirectory>docs</reportOutputDirectory>
</configuration>
</plugin>
These typically have version numbers specified. How do you know which version to use?
Here are two ways:
Getting Versions from Maven Central
At this site, you can search for dependencies and plugins and find the various versions, along with the Maven xml element to copy past and
put into your pom.xml
:
A plugin to help manage dependency versions
This plugin helps manage dependency versions:
This Stack Overflow answer offers one example of how to use it:
Using the org.codehaus.mojo.versions-maven-plugin
(These instructions are from https://stackoverflow.com/a/19324681)
Add this plugin under the <build>
section
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
...
</plugins>
...
</build>
...
</project>
This command will create a backup of the pom.xml
called pom.xml.versionsBackup
mvn versions:set -DnewVersion=9.9.9
Then run this, which updates the pom.xml
mvn versions:use-latest-versions
You can then run:
diff pom.xml pom.xml.versionsBackup
Test with the new versions. You may want to then set the version in the pom.xml
back to what it was before.
Related topics:
- Maven: Hello World—A relatively simple Hello World app with Maven
- Maven: Adding custom jar dependency—Including a jar file that isn't available as a standard Maven dependency
- Maven: Convert Ant to Maven—replacing ant build.xml with maven pom.xml
- Maven: FAQ—Frequently Asked Questions
- Maven: Installing—on Windows, Mac, Linux
- Maven: Javadoc—Generating javadoc when using Maven
- Maven: Managing Versions—How do you get the right version for dependencies, plugins, etc.
- Maven: Pom.xml Order—In what order should the elements of a pom.xml appear
- Maven: Profiles—Making your pom.xml do different things on localhost vs heroku, for example
- Maven: Testing—Doing JUnit testing and other testing using mvn test, mvn verify, etc.
- Maven: Wrapper—The mvnw file that you see in some repos: what is it, and why do you need it
- Maven: Xlint options—For example, what to do when you get `Recompile with -Xlint:unchecked for details`