Friday, November 15, 2013

Useful Maven Commands

Overview

Previous post I have described some basic concepts of Apache Maven. Here I have included some useful commands need for day to day maven operations.

Maven Commands


Maven Commands
Maven command
Usage
mvn --version
Get the  maven version of your computer.
mvn archetype:generate
Create a maven project based on 40 + maven templates. You can specify the template by entering the number after this.
eg. 18 for simple Java web application project template

mvn archetype:generate -DarchetypeGroupId=
org.apache.maven.archetypes -DgroupId=com.mycompany.app \ -DartifactId=my-app
Create default maven project with my-app directory and pom.xml
mvn compile
Compile your project sources.
mvn test
Executes their unit tests.
mvn package
Package will compile your code and also package it. For example, if your pom says the project is a jar, it will create a jar for you when you package it and put it somewhere in the target directory (by default).
mvn install
Compile and package, but it will also put the package in your local repository. This will make it so other projects can refer to it and grab it from your local repository.

mvn deploy
Copies the final package to the remote repository for sharing with other developers and projects.
mvn clean
Removes files generated at build-time in a project's directory (target by default). It will also remove caches of previous 
mvn clean install
First clean  and then install. You can combine some operations like that based on the each operations.
mvn idea:idea
Generate settings and files needed for IDEA maven project. This will remove the errors with imports in your java project
mvn eclipse:eclipse
Same thing for ECLIPSE maven project.
MAVEN_OPTS=”-Xms1024m -Xmx4096m -XX:MaxPermSize=1024m”
Avoid the Maven OutOfMemoryError

Maven Command Line Options


We can add additional arguments to basic operations. maven eg.mvn install -Dmaven.test.skip=true

Maven Command Line Options
Maven argumentUsage
mvn install -o
Compiles, tests, packages and installs the jar or war file in offline mode
-Dmaven.test.skip=true
Skip tests would not even compile the tests
-Dmaven.test.failure.ignore= true
Ignore any failures occurred during test execution
-Dmaven.test.error.ignore=true
Ignore any errors occurred during test execution
-DskipTests
Compile the test classes but skip test execution entirely
--fail-fast
The default behavior - whenever a module build fails, stop the overall build immediately
--fail-at-end
If a particular module build fails, continue the rest of the reactor and report all failed modules at the end instead
--resume-from
Resumes a reactor the specified project (e.g. when it fails in the middle)

No comments :

Post a Comment