Replace Variations: Dependencies in Maven Initiatives – DZone – Uplaza

With the passing of time, new variations of the dependencies are launched into the market. We have to replace the respective dependencies variations within the venture as these variations have new modifications and fixes for the safety vulnerabilities. It’s higher to replace the dependencies steadily within the venture. 

Now arises the query:

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

It’s a very tedious process to manually examine which dependencies have launched a brand new model after which go to your pom.xml file and replace every manually. When you’ve got an enormous venture and are utilizing a number of dependencies, it is extremely tedious to seek for every dependency and examine if there’s a model improve accessible.

How To Test for Availability of Newer Variations for the Dependencies within the Maven Mission

Fortunately, Maven has supplied us with a command that by operating you’ll get to know which dependencies in your venture should be upgraded with the newest model launch. We have to merely open the command immediate or terminal in our native machine, run the next Maven command, and it’ll present you all of the dependencies which have newer variations so you possibly can replace them in your venture! How cool it’s!

mvn variations:display-dependency-updates

I received an enormous aid once I realized about this, and now I merely run the command and get all of the updates in regards to the dependencies within the venture.

Let’s run this command and examine the output it delivers. I’m operating this command on the repository which has API Automation Instance Exams and makes use of a number of dependencies like rest-assured, testng, jackson-databind, and so forth.

It may be seen within the above screenshot that Maven shows that there are newer variations accessible for the next dependencies with their respective older and newer variations:

Dependency Title Previous Model New Model
jackson-databind   2.15.2 2.17.2
io.qmeta.attract  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 stress-free to see the leads to a number of seconds and discover out precisely what dependencies in your venture should be up to date to the newest model.

Now arises one other query: 

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

The reply to this query will probably be supplied within the following part of this text. 

How To Test for Availability of Newer Variations for the Plugins within the Maven Mission

Equally to how we ran the command for locating the newest variations of the dependencies, we will run one other Maven command and discover out in regards to the updates associated to the Maven plugins used within the venture.

mvn variations:display-plugin-updates

On executing the above command on the foundation folder of the venture, the next output is printed.

It may be seen that Maven has supplied us with all of the plugin-related data that can be utilized and up to date in pom.xml. It has additionally listed down the required Maven model for updating the respective plugins.

Updating the Dependency Variations within the Mission

Now, the subsequent course of is to replace the dependencies within the venture which Maven has supplied us with the newest variations for. Now, there are 2 choices accessible to replace the dependencies:

  1. Manually replace the variations in pom.xml.
  2. Use the Maven command to replace the dependencies routinely.

Updating pom.xml With the Newest Variations of the Dependencies Utilizing Maven Command

There are two circumstances right here by way of replace:

  1. Dependency variations are supplied within the Dependency itself.
  2. Dependency variations are up to date within the properties block in pom.xml.

To Replace the Dependency Model within the Dependency Itself

When you’ve got the variations outlined within the dependency itself, run the next command:

mvn variations: use-latest-versions

Within the pom.xml earlier than operating the command, we will see that the model for testng is 7.10.0 and for rest-assured it’s 5.4.0.

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

Now let’s examine the pom.xml file and see if the variations had been up to date to the newest one.

The variations received up to date routinely after the command was executed efficiently. We will see that testng dependency has the newest model 7.10.2 and rest-assured has the newest model as properly, which is 5.5.0.

Maven created a backup pom.xml file (examine the file named pom.xml.versionsBackup within the screenshot under) within the root folder, simply in case we need to revert again the modifications.

To Replace Dependency Variations That Are Up to date within the Properties Block:

When you’ve got the variations outlined within the properties block within the pom.xml, run the next command:

mvn variations:update-properties

Let’s run the command and take a look at the automated replace of the variations within the properties block of pom.xml file.

The variations we see within the pink coloration within the above screenshots had been up to date routinely via the command we simply executed.

Maven created a backup pom.xml file (examine the file named pom.xml.versionsBackup within the screenshot under) within the root folder simply in case we need to revert again the modifications.

Abstract

The tedious process of manually discovering the newer variations of the respective dependencies and updating them will be simply carried out utilizing the mvn:variations command. We will sit again and revel in a sizzling cup of espresso whereas Maven updates the dependencies routinely within the venture for us.

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version