Maven is a build tool, mainly used to build and manage java projects.
- Download Maven and follow the installation instructions
- run
mvn --version
to confirm the installation - Create a sample project from existing templates (called
archetype
) or create one by yourself - Check How IntelliJ IDEA supports maven
- The core of
mvn project
is pom.xml (pom
refers toProject Object Model
) - It is a single configuration file that contains the majority of information required to build a project in just the way you want
- It has 3 important elements
groupId
- indicates the unique identifier of the organization or groupartifactId
- indicates the unique base name of the primary artifact being generated by this project. For exampleJAR
nameversion
- version of the project
validate
- validates the maven project that everything is correct and all the necessary information is availablecompile
- compile the source code of the projecttest
- test the compiled source code using a suitable unit testing framework. These tests should not require the code to be packaged or deployedpackage
- take the compiled code and package it in its distributable format, such as a JARintegration-test
- process and deploy the package if necessary into an environment where integration tests can be runverify
- run any checks to verify the package is valid and meets quality criteriainstall
- install the package into the local repository, for use as a dependency in other projects locallydeploy
- done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projectsclean
- clean up artifacts created by prior buildssite
- generates site documentation for this project
-
mvn clean
- will clear all the artificates present in the project folder- clears
target
directory present in the project folder
- clears
-
mvn compile
- compiles all the source codes of the project- For example,
.java
files present in themain
andtest
- For example,
-
mvn test
- executes the test cases present in the project- As a result, you will get the status something like this
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
- As a result, you will get the status something like this
-
mvn package
- takes all the compiled source and package them as a jarJAR
can be found insidetarget
directory, ex:/home/${USER}/workspace/hello-maven/target/hello-maven-1.0-SNAPSHOT.jar
-
mvn install
- copy the generatesJAR
into local repo, so that other projects can make use of this work- your
JAR
will be moved to/home/${USER}/.m2/repository/com/hod/hello-maven/1.0-SNAPSHOT/hello-maven-1.0-SNAPSHOT.jar
- your
We can execute multiple phases or goals in a single line. For example,
mvn clean compile package
- https-//maven.apache.org/guides/getting-started/maven-in-five-minutes.html
- https://www.journaldev.com/33645/maven-commands-options-cheat-sheet