Project Dependencies in Maven

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”
         xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>
    <modelVersion>4.0.0</modelVersion>

    
    <groupId>com.Seleniumbix.Framework</groupId>
    <artifactId>SeleniumBixFramework</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Sample Automation project</name>
    
    <dependencies>
    <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.6.1</version>
        </dependency>
        
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>org.easytesting</groupId>
            <artifactId>fest-assert</artifactId>
            <version>1.4</version>
        </dependency>
    </dependencies>
    </project>

 

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.

0 Comment

Leave a Reply