Maven - Dependency


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




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




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

Powered by ComboStrap