First of all, build is not a phase in the standard Maven lifecycles, whereas install is one. mvn install will invoke all the phases up to the phase install , which generally consists of compiling the source code, packaging the project and installing it in the local repository.
Maven is a popular open-source build tool developed by the Apache Group to build, publish, and deploy several projects at once for better project management. The tool provides allows developers to build and document the lifecycle framework.
Maven Install Command: mvn install
The Install Plugin uses the information in the POM (groupId, artifactId, version) to determine the proper location of the artifact within the local repository. The mvn deploy runs the deploy plugin which deploys an artifact to the remote repository.
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.
We execute project testing steps with the mvn test command. We can compile the test source code by using the mvn test-compile command. The mvn install command aids in the deployment of packaged WAR or JAR files by storing them in the local repository as classes.
In the Maven project, you can create and run tests the same way you do in any other project using the default IntelliJ IDEA test runner.
On a mvn install, it frames a dependency tree based on the project configuration pom. xml on all the sub projects under the super pom. xml (the root POM) and downloads/compiles all the needed components in a directory called . m2 under the user's folder.
mvn clean install tells maven to do the clean phase in each module before running the install phase for each module. mvn clean is its own build lifecycle phase (which can be thought of as an action or task) in maven. In Maven terms: clean is a phase of the clean lifecycle.
Maven avoids the need to discover and specify the libraries that your own dependencies require by including transitive dependencies automatically. This feature is facilitated by reading the project files of your dependencies from the remote repositories specified.
"install" refers to the process of installing an artifact in your local repository. "deploy" refers to the process of deploying an artifact to a remote repository. Example: When I run a large multi-module project on a my machine, I'm going to usually run "mvn install".
Default Packaging Types. Maven offers many default packaging types that include a jar, war, ear, pom, rar, ejb, and maven-plugin. Each packaging type follows a build lifecycle that consists of phases. Usually, every phase is a sequence of goals and performs a specific task.
Pip installs system and project-level Python packages. Maven manages dependencies and the build process for Java projects.
There are three built-in build lifecycles: default, clean and site.
Define a simple Maven build
Maven projects are defined with an XML file named pom. xml. Among other things, this file gives the project's name, version, and dependencies that it has on external libraries.
What is a POM? A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.
A BOM is a special kind of POM that is used to control the versions of a project's dependencies and provide a central place to define and update those versions. BOM provides the flexibility to add a dependency to our module without worrying about the version that we should depend on.
A Maven pom defines the project structure including the stated dependencies. A bom defines the complete bill of materials of what dependencies are actually used - the effective dependencies.
mvn clean install is the command to do just that. You are calling the mvn executable, which means you need Maven installed on your machine. (see How do you install Maven?) You are using the clean command, which will delete all previously compiled Java .
To verify whether maven is installed or not, open the command prompt and write: mvn −version.
Improved performance
A clean install can improve computer performance and speed, which may not be possible with an in-place upgrade, especially on an old system that's been running the same version for a long time. A clean install can give your Windows registry a fresh start.
The mvn install command, however, additionally to compiling the source code and packaging it into a JAR or a WAR, it will also install the package into the local repository, for use as a dependency in other projects locally.
Maven automatically downloads your project's dependencies, whenever you run a build.
Maven's local repository is a directory on the local machine that stores all the project artifacts. When we execute a Maven build, Maven automatically downloads all the dependency jars into the local repository. Usually, this directory is named . m2.