Maven - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Maven Dependency

Maven Dependency

shape Introduction

Maven Dependency chapter explains about Dependency, Dependency Resolution and External Dependencies.

shape Description

When there is a big project, it has to be updated frequently. To automate, the project's external JAR files have to be added. Downloading these external dependencies(JAR Files) and adding them to the existing dependencies with the correct version is a difficult task. When a package is compiled, pom.xml file will check the Dependency information in the repository for any further jars to be included. Maven manages all these dependencies by default.

shape Examples

The following example consists of pom file with dependencies in the dependency element. [xml] <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.splessons.crawler</groupId> <artifactId>java-web-crawler</artifactId> <version>1.0.0</version> <dependencies> <dependency> <groupId>org.itoolsinfo</groupId> <artifactId>itoolsinfo</artifactId> <version>1.7.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> </build> </project>[/xml] In the above example, two dependencies org.splessons and itoolsinfo are downloaded from the central repository and are kept in the Local repository if they are not downloaded from the local repository.

Dependency Resolution

shape Description

Every project can give its own dependencies using unique identifiers of components. While building the projects, Maven resolves the module dependencies that are already built in the following order. Maven Reactor is required when the projects in the same Maven have to run.

External Dependencies

shape Description

External dependencies are the dependencies that are not present in the Maven repository system.

shape Examples

Configuration of external dependencies can be done as follows: [xml] <dependency> <groupId>mydependency</groupId> <artifactId>mydependency</artifactId> <scope>system</scope> <version>1.0</version> <systemPath>${basedir}\war\WEB-INF\lib\mydependency.jar</systemPath> </dependency>[/xml] In the above example, ${basedir} points to POM directories.

Summary

shape Key Points

  • Dependencies are the jar files.
  • External dependencies are added to the repository system externally.