My mvn notes

To skip running tests:
mvn install -DskipTests
mvn install -DskipTests=true //to override skipTests property in pom
To skip compiling and running tests:
mvn install -Dmaven.test.skip=true
To run maven in offline mode, to avoid downloading:
mvn -o install
mvn --offline install
To force check for updates of snapshots and releases from remote repositories:
mvn -U install
mvn --update-snapshots install
To override maven surefire plugin forkMode:
mvn test -DforkMode=never
mvn test -DforkMode=always
To debug a non-forked test, just need to attach the remote debugger to mvn process itself. mvnDebug is a convenience script located in the same directory as mvn executable:
mvnDebug test
mvnDebug test -DforkMode=never
To debug a forked test, you will need to set the debug option to the forked VM, not the mvn VM. The way to do it is to set -Dmaven.surefire.debug flag to mvn VM (the parent VM):
mvn test -Dmaven.surefire.debug
mvn test -Dmaven.surefire.debug -DforkMode=always
mvn test -Dmaven.surefire.debug -Dtest=com.my.test.MyTest#test1
To avoid OutOfMemoryError from running maven, especially maven 3, set environment variable MAVEN_OPTS:
# in $HOME/.tcshrc, or $HOME/.cshrc, if using csh or tcsh:
setenv MAVEN_OPTS "-Xmx1024m -XX:MaxPermSize=256m"

# in $HOME/.profile or $HOME/.bashrc, if using ksh or bash:
export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=256m"

# in Windows Control Panel, or set it in DOS command line (This is Windows. DO NOT quote values):
set MAVEN_OPTS=-Xmx1024m -XX:MaxPermSize=256m

To run individual unit test, use -Dtest system property. Copy reference on the test method in IDE to get the full test name (command-option-shift-c in Intellij on Mac):
mvn install -Dtest=test.UserTest#testNewUser
mvn test -Dtest=test.UserTest#testNewUser

To run individual integration test, use -Dit.test system property:
mvn install -Dit.test=test.UserTestIT#testLogin
mvn verify -Dit.test=test.UserTestIT#testLogin
mvn integration-test -Dit.test=test.UserTestIT#testLogin

To pass environment variables to tests executed with maven surefire plugin:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<environmentVariables>
<JAVA_HOME>${env.JAVA_HOME}</JAVA_HOME>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

To pass system properties to integration tests executed with failsafe plugin:
    <build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.11</version>
<configuration>
<systemPropertyVariables>
<project.build.directory>${project.build.directory}</project.build.directory>
<project.artifactId>${project.artifactId}</project.artifactId>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

To run mvn with an alternate user setting file, e.g., settings-jboss.xml:
mvn -s $HOME/.m2/settings-jboss.xml
The content of settings-jboss.xml:
<settings>
<repositories>
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
</settings>
When including mvn command in a Windows batch file, use call command.
call mvn clean install
cd integration-tests
call mvn clean install

Followers

Pageviews Last 7 Days