[java] What does mvn install in maven exactly do

I just started using Maven and I was told to do mvn install in a specific directory.

What does mvn install do, exactly?

I think it looks for pom.xml in the current folder and starts following the instructions specified in that file. Is that correct?

This question is related to java maven pom.xml

The answer is


Have you looked at any of the Maven docs, for example, the maven install plugin docs?

Nutshell version: it will build the project and install it in your local repository.


mvn install primary jobs are to 1)Download The Dependencies and 2)Build The Project

while job 1 is nowadays taken care by IDs like intellij (they download for any dependency at POM)

mvn install is majorly now used for job 2.


The install:install goal is provided by «Apache Maven Install Plugin»:

Apache Maven Install Plugin

The Install Plugin is used during the install phase to add artifact(s) to the local repository. The Install Plugin uses the information in the POM (groupId, artifactId, version) to determine the proper location for the artifact within the local repository.

The local repository is the local cache where all artifacts needed for the build are stored. By default, it is located within the user's home directory (~/.m2/repository) but the location can be configured in ~/.m2/settings.xml using the <localRepository> element.

Apache Maven Install Plugin - Introduction.

Having said that, the exact goal purpose:

install:install is used to automatically install the project's main artifact (the JAR, WAR or EAR), its POM and any attached artifacts (sources, javadoc, etc) produced by a particular project.

Apache Maven Install Plugin - Introduction.

For additional details on the goal, please refer to the Apache Maven Install Plugin - install:install page.

For additional details on the build lifecycle in general and on which place the goal has in the build lifecycle, please refer to the Maven – Introduction to the Build Lifecycle page.


-DskipTests=true is short form of -Dmaven.test.skip=true

Make changes in Setting.xml in your .m2 folder. You can use link to local repo so that the jars once downlaoded should not be downloaded again and again.

<url>file://C:/Users/admin/.m2/repository</url>
 </repository>

It will run all goals of all configured plugins associated with any phase of the default lifecycle up to the "install" phase:

https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference


At any stage of maven build life cycle, all the previous goals are performed.

Ex: mvn install will invoke mvn validate, mvn compile, mvn test, mvn package etc.


Short answer

mvn install

  • adds all artifact (dependencies) specified in pom, to the local repository (from remote sources).

It's important to point out that install and install:install are different things, install is a phase, in which maven do more than just install current project modules artifacs to local repository, it check remote repository first. On the other hand, install:install is a goal, it just build your current project and install all it's artifacts to local repository (e.g. into the .m2 directory).


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to maven

Maven dependencies are failing with a 501 error Why am I getting Unknown error in line 1 of pom.xml? Why am I getting "Received fatal alert: protocol_version" or "peer not authenticated" from Maven Central? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Unable to compile simple Java 10 / Java 11 project with Maven ERROR Source option 1.5 is no longer supported. Use 1.6 or later 'react-scripts' is not recognized as an internal or external command How to create a Java / Maven project that works in Visual Studio Code? "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository Java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException

Examples related to pom.xml

Why am I getting Unknown error in line 1 of pom.xml? Maven:Non-resolvable parent POM and 'parent.relativePath' points at wrong local POM Meaning of ${project.basedir} in pom.xml Maven and Spring Boot - non resolvable parent pom - repo.spring.io (Unknown host) Maven: How do I activate a profile from command line? repository element was not specified in the POM inside distributionManagement element or in -DaltDep loymentRepository=id::layout::url parameter What is <scope> under <dependency> in pom.xml for? The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path Maven error in eclipse (pom.xml) : Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4 Missing artifact com.oracle:ojdbc6:jar:11.2.0 in pom.xml