Maven - Dependency

Card Puncher Data Processing


dependency management in Maven.

Dependency are artifact where your software depends on.

Dependency are defined in the pom.xml, section dependencies.


When you build an application, Maven will search for dependencies in the local repository. If a stable version is not found there, it will search the remote repositories to retrieve this dependency. Then, it will copy it into the local repository, to make it available for the next builds.


The dependency management section is a mechanism for:

  • centralizing dependency information.


mvn dependency:analyze


mvn dependency:resolve



mvn dependency:get -Dartifact=group:name:version 

You can also specify a remote repository Url with -DremoteRepositories=Url


mvn dependency:list -DoutputAbsoluteArtifactFilename=true -DoutputFile=dependencies.txt


mvn dependency:tree

Exclude children

In case of dependency hell …



Snapshot Fetch

According to snapshot default updatePolicy, maven will fetch the snapshot artifact from the repository on daily basis. See snapshot configuration

mvn clean install -U



Dependency Property as defined in the pom.xml, section dependencies.


This element refers to the classpath of the task at hand (compiling and runtime, testing, etc.) as well as how to limit the transitivity of a dependency. There are five scopes available:

  • compile - (default). Compile dependencies are available in all classpaths. Furthermore, those dependencies are propagated to dependent projects.
  • provided - like compile, and indicates that you expect it to be provided at runtime by the JDK or a container.
  • runtime - this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.
  • test - this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.
  • system - this scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.


Artifact's packaging type (defaults to jar)


Maven - Package ??

Artifact's identifier

Artifact's identifier: Maven - Artifact - (Component|Module|Library)




For dependency that are not open source, the artifact must be installed in a not public repository.

For an installation on:

Example with an Oracle 's driver installation in the local maven repository as follows:

cd $ORACLE_HOME/jdbc/lib
mvn install:install-file -DartifactId=ojdbc6 -Dversion= -Dpackaging=jar -Dfile=ojdbc6.jar -DgeneratePom=true

Copy / download

Copy = Download dependency from the repository.

With the mvn command tool:

mvn dependency:copy-dependencies

Example of Usage: Dos bat file that download all jar dependency in a output directory, then call a main class

@echo off

if not exist target\dependencies (call mvn -B dependency:copy-dependencies -DoverWriteReleases=false -DoverWriteSnapshots=false -DoverWriteIfNewer=true -DoutputDirectory=target\dependencies)

java -Xmx1G -cp ".\target\dependencies\*" package.mainClass --verbose=true %*

Build dependency classpath

Build the class path

mvn dependency:build-classpath -Dmdep.outputFile=target/classpath.txt


What is a Dependency Tree or Graph?

mvn dependency:tree

Idea Maven Dependency Tree



Could not resolve dependencies for project

If maven can't resolve reactor module, this is because you need to install them first

mvn clean install

Documentation / Reference

Discover More
Java Conceptuel Diagram
Java - Axis (Web Services / SOAP / WSDL engine)

Axis is a Web Services client generation engine. Download the binary distribution And unzip it Add the bin directory in the path Set...
Card Puncher Data Processing

is a build tool. It is declarative build tool whereas ant is a procedural build tool. You can then change the build process by changing the process not the declaration. Most of the project declaration...
Card Puncher Data Processing
Maven - (Remote Repository|Server)

Remote repository in maven A remote repository (or server) can be defined as: a source to resolve dependency (via HTTP) or as a target to deploy the artifact (via SCP) The definition dependent on...
Card Puncher Data Processing
Maven - Artifact - (Component|Module|Library)

in Maven. An Artifact is the data storage unit of a repository. It's at the same time: the distribution unit to distribute and the dependency unit to use (Ie artifacts can be transferred to...
Card Puncher Data Processing
Maven - ClassPath

in Maven The classpath is a component of dependency. You can use it to create your own command. Example:
Card Puncher Data Processing
Maven - JRE (Including it in your distribution)

A JRE is just a dependency Therefore you can upload it to a repository and use it in your build. With a file named, we will get the following artifact coordinates: ...
Card Puncher Data Processing
Maven - Mvn

-t,--toolchains -U,--update-snapshots Forces a check for updated releases and snapshots on remote repositories -up,--update-plugins Ineffective, only kept for backward compatibility -V,--show-version...
Card Puncher Data Processing
Maven - Phase (Build lifecycle)

A phase is a step in the build lifecycle, which is an ordered sequence of phases. When a phase is given, Maven will execute every phase in the sequence up to and including the one defined. Phases are...
Card Puncher Data Processing
Maven - Plugin (Mojo)

A plugin (in Maven 2.0) groups together goals by code. It's an independent unit of code for Maven. It look like a dependency. In Maven, there are: Build plugins. They will be executed during the...
Card Puncher Data Processing
Maven - Project

A project in the Maven sense contains all little pieces that come into play to give code life. Ie: configuration files, the developers involved and the roles they play, the defect tracking system,...

Share this page:
Follow us:
Task Runner