Apache Maven is a project management and automation tool for Java software projects. It is used to automate continuous integration during software development. The goal is to produce software from its sources by optimizing the tasks performed for this purpose and ensuring the correct build order.
In this guide, we will cover some useful Maven commands.
Clean and install the application locally
mvn clean install
Update snapshot: Force the check of missing versions and updated snapshots on remote repositories
mvn clean install -U
Skip tests during installation
mvn install -DskipTests
Do not compile tests
mvn install -Dmaven.test.skip=true
Run a test class
mvn clean test -Dtest=ClassDeTest
mvn clean test -Dtest=ClassDe*
Run a single test
mvn clean test -Dtest=ClassDeTest#monTest
Install local libraries
mvn validate
Clean builds
mvn clean
Compile + Test + Build WAR/JAR
mvn package
Deploy the application (example: Nexus)
mvn deploy
Generate the website (Documentation)
mvn site
Prepare a release (commit git and tag)
mvn release:prepare
Perform the release (example: deploy to Nexus)
mvn release:perform
Show dependencies with updates available
mvn versions:display-dependency-updates
Show the dependency tree of the POM
mvn dependency:tree
Use one or more profiles
mvn -P profil-1
mvn -P profil-1,profil-2
Get a status report of vulnerabilities in dependencies used
Add the following plugin to the pom.xml file:
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>7.1.0</version>
</plugin>
Then, execute the following command to get the status report (the created file containing the information will be in target/dependency-check-report.html):
mvn dependency-check:check
For more information: https://www.baeldung.com/maven
LauLem.com - (Pages in French) Conditions of Use - Legal Information - Cookie Policy - Personal Data Protection Policy - About