Let’s learn about the Project Dependencies in Maven. Your project needs external Java API’s or Framework to compile and execute and these utilities are packaged in their own JAR files.
Project Dependencies in Maven
Keeping your project up-to-date with the correct versions of these external JAR files can be a comprehensive task. Each external JAR may again also need other external JAR files etc. Downloading all these external dependencies (JAR files) recursively and making sure that the right versions are downloaded is a difficult job.
Here Maven helps us as Maven has built-in dependency management. You need to specify these JARs or external files in the POM file and then Maven downloads them for you and puts them in your local Maven repository. If any of these external libraries need other libraries, then these other libraries are also downloaded into your local Maven repository.
You need to specify dependencies inside the dependencies element in the POM file of your project. Let’s see an example –
<?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”
<name>Sample Automation project</name>
You can note above pom.xml file, Here we have added three dependencies. Each dependency is described by its groupId, artifactId, and version. You may remember that this is also how you identified your own project in the beginning of the POM file.
When this POM file is executed by Maven, the three dependencies will be downloaded from a central Maven repository and put into your local Maven repository. If the dependencies are already found in your local repository, Maven will not download them. Only if the dependencies are missing will they be downloaded into your local repository.
Using this way, You can manage the External dependencies for your Project using Maven.