DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Maven Dependency Scope Applied
  • How To Approach Dependency Management in Java [Video]
  • How To Convert Image Files Into GIF or WebP Format Using Java
  • How To Validate Names Using Java

Trending

  • A Guide to Container Runtimes
  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide
  • Contextual AI Integration for Agile Product Teams
  • How to Format Articles for DZone
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. How to Check and Update Newer Versions for Dependencies in Maven Projects

How to Check and Update Newer Versions for Dependencies in Maven Projects

This tutorial demonstrates how to use different Maven commands for checking and updating the dependency and plugin versions in Maven projects.

By 
Faisal Khatri user avatar
Faisal Khatri
DZone Core CORE ·
Aug. 07, 24 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
10.1K Views

Join the DZone community and get the full member experience.

Join For Free

With the passing of time, new versions of the dependencies are released into the market. We need to update the respective dependencies versions in the project as these versions have new changes and fixes for the security vulnerabilities. It is better to update the dependencies frequently in the project. 

Now arises the question:

“How do I come to know which dependencies have a new version released and need to be updated?”

It is a very tedious task to manually check which dependencies have released a new version and then go to your pom.xml file and update each manually. If you have a big project and are using multiple dependencies, it is very tedious to search for each dependency and check if there is a version upgrade available.

How to Check for Availability of Newer Versions for the Dependencies in the Maven Project

Luckily, Maven has provided us with a command that by running you will get to know which dependencies in your project need to be upgraded with the latest version release. We need to simply open the command prompt or terminal in our local machine, run the following Maven command, and it will show you all the dependencies that have newer versions so you can update them in your project! How cool it is!

mvn versions:display-dependency-updates


I got a huge relief when I learned about this, and now I simply run the command and get all the updates about the dependencies in the project.

Let’s run this command and check the output it delivers. I am running this command on the repository which has API Automation Example Tests and uses multiple dependencies like rest-assured, testng, jackson-databind, etc.

Command output

It can be seen in the above screenshot that Maven displays that there are newer versions available for the following dependencies with their respective older and newer versions:

Dependency Name Old Version New Version
jackson-databind   2.15.2 2.17.2
io.qmeta.allure  2.27.0 2.28.1
json-schema-validator  5.4.0 5.5.0
rest-assured 5.4.0 5.5.0
data-faker 2.2.2 2.3.1
commons-lang3 3.14.0 3.15.0
log4j-api 2.22.1 3.0.0-beta2
log4j-core 2.22.1 3.0.0-beta2
testng 7.10.0 7.10.2

It’s so relaxing to see the results in a few seconds and find out exactly what dependencies in your project need to be updated to the latest version.

Now arises another question: 

"Is there any Maven command to check and update the plugin versions in pom.xml?" 

The answer to this question will be provided in the following section of this article. 

How to Check for Availability of Newer Versions for the Plugins in the Maven Project

Similarly to how we ran the command for finding the latest versions of the dependencies, we can run another Maven command and find out about the updates related to the Maven plugins used in the project.

mvn versions:display-plugin-updates


On executing the above command on the root folder of the project, the following output is printed.

Output: command on the root folder of the project

It can be seen that Maven has provided us with all the plugin-related information that can be used and updated in pom.xml. It has also listed down the required Maven version for updating the respective plugins.

Updating the Dependency Versions in the Project

Now, the next process is to update the dependencies in the project which Maven has provided us with the latest versions for. Now, there are 2 options available to update the dependencies:

  1. Manually update the versions in pom.xml.
  2. Use the Maven command to update the dependencies automatically.

Updating pom.xml With the Latest Versions of the Dependencies Using Maven Command

There are two cases here in terms of update:

  1. Dependency versions are provided in the Dependency itself.
  2. Dependency versions are updated in the properties block in pom.xml.

To Update the Dependency Version in the Dependency Itself

If you have the versions defined in the dependency itself, run the following command:

mvn versions: use-latest-versions


In the pom.xml before running the command, we can see that the version for testng is 7.10.0 and for rest-assured it is 5.4.0.

Version for testng is 7.10.0 and for rest-assured it is 5.4.0

Let’s run the mvn versions:use-latest-versions by navigating to the root folder of the repository.

run the mvn versions:use-latest-versions by navigating to the root folder of the repository

Now let’s check the pom.xml file and see if the versions were updated to the latest one.

check the pom.xml file and see if the versions got updated

The versions got updated automatically after the command was executed successfully. We can see that testng dependency has the latest version 7.10.2 and rest-assured has the latest version as well, which is 5.5.0.

Maven created a backup pom.xml file (check the file named pom.xml.versionsBackup in the screenshot below) in the root folder, just in case we want to revert back the changes.

Backup pom.xml file

To Update Dependency Versions That Are Updated in the Properties Block:

If you have the versions defined in the properties block in the pom.xml, run the following command:

mvn versions:update-properties


Let’s run the command and check out the automatic update of the versions in the properties block of pom.xml file.

Automatic update of the versions in the properties block of pom.xml file


rest-assured version


Versions were automatically updated

The versions we see in the red color in the above screenshots were updated automatically through the command we just executed.

Maven created a backup pom.xml file (check the file named pom.xml.versionsBackup in the screenshot below) in the root folder just in case we want to revert back the changes.

pom.xml.versionsBackup

Summary

The tedious task of manually finding the newer versions of the respective dependencies and updating them can be easily done using the mvn:versions command. We can sit back and enjoy a hot cup of coffee while Maven updates the dependencies automatically in the project for us.

Apache Maven TestNG Command (computing) Dependency

Published at DZone with permission of Faisal Khatri. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Maven Dependency Scope Applied
  • How To Approach Dependency Management in Java [Video]
  • How To Convert Image Files Into GIF or WebP Format Using Java
  • How To Validate Names Using Java

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!