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 mission as these variations have new modifications and fixes for the safety vulnerabilities. It’s higher to replace the dependencies continuously within the mission.
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 job 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 mission and are utilizing a number of dependencies, it is vitally tedious to seek for every dependency and examine if there’s a model improve out there.
How To Test for Availability of Newer Variations for the Dependencies within the Maven Challenge
Fortunately, Maven has offered us with a command that by operating you’ll get to know which dependencies in your mission must 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’ll be able to replace them in your mission! How cool it’s!
mvn variations:display-dependency-updates
I received an enormous reduction once I realized about this, and now I merely run the command and get all of the updates concerning the dependencies within the mission.
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 out there for the next dependencies with their respective older and newer variations:
Dependency Identify | 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 enjoyable to see the leads to a number of seconds and discover out precisely what dependencies in your mission must 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 offered within the following part of this text.
How To Test for Availability of Newer Variations for the Plugins within the Maven Challenge
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 concerning the updates associated to the Maven plugins used within the mission.
mvn variations:display-plugin-updates
On executing the above command on the basis folder of the mission, the next output is printed.
It may be seen that Maven has offered 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 Challenge
Now, the subsequent course of is to replace the dependencies within the mission which Maven has offered us with the newest variations for. Now, there are 2 choices out there to replace the dependencies:
- Manually replace the variations in pom.xml.
- 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 instances right here when it comes to replace:
- Dependency variations are offered within the Dependency itself.
- 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 basis 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 nicely, which is 5.5.0
.
Maven created a backup pom.xml file (examine the file named pom.xml.versionsBackup within the screenshot beneath) within the root folder, simply in case we wish 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 purple coloration within the above screenshots had been up to date routinely by means of the command we simply executed.
Maven created a backup pom.xml file (examine the file named pom.xml.versionsBackup within the screenshot beneath) within the root folder simply in case we wish to revert again the modifications.
Abstract
The tedious job of manually discovering the newer variations of the respective dependencies and updating them could be simply performed 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 mission for us.