Useful Maven commands

Here’s a list of some useful maven commands.

Display maven information

mvn help:evaluate -Dexpression=spring-data-releasetrain.version

Sometimes it is useful to know the value of certain properties. If you need to evaluate a certain expression on the command line and display the result you can use the help maven plugin.

Debug unit (surefire) tests from command line:

mvn -Dmaven.surefire.debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000" test

You need these parameters because the tests are forked. However, we don’t use this command that often because unit tests are really easy to debug from your IDE.

Debug integration (failsafe) tests from command line:

mvn -Dmaven.failsafe.debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000" verify -Ptest
It’s a good idea to make an alias to shorten these commands. For instance mci could be an alias for mvn clean install and mcid could be an alias for the above long debug command.

Run a single integration test from command line:

You can also debug a single test using the following:

mvn clean install -Ptest -Dit.test=MyTest

You can also specify a method inside a test-case, using -Dit.test=MyTest#myMethod or several methods using -Dit.test=MyTest#testOne+testTwo or you can specify a package for your test (more examples here):

mvn clean install -Ptest -Dit.test=**mobile**/AccountViewControllerSeleniumIntegrationTest#testAccountOrderEntryPage

Stop maven attempt to download snapshot versions

You can tell maven to not check for any newer snapshot versions. Just you the --no-snapshot-updates or even shorter -nsu option like this:

mvn clean install -nsu

Resolve dependency conflicts

Sometimes maven will bring transitive dependencies which you have no idea where they come from. When this happens, use the maven-dependency-plugin to create a tree of the dependencies and their parents:

mvn dependency:tree -Dverbose

Prepare the site documentation

The documentation of the nemesis platform is written in asciidoc and is built using the maven-site-plugin. To prepare the documentation for a given module all you need is to create a site with maven:

mvn clean site -o

This will prepare the site in an offline mode (a lot faster as we use tons of SNAPSHOT dependencies). You can also combine all the submodules together and see how the finished site will look like:

mvn site:stage

or if you want to see the site for a module, but don’t want to create it’s submodules:

mvn clean site -o -pl .

Check for dependency updates.

From time to time it’s good to check which dependencies have new versions. You can do this with the following command executed from the root of the project.

mvn versions:display-dependency-updates

Usually we run this command in the nemesis-bom project after each subsequent release so that the next release targets newer versions of the dependencies.

Tidy your poms

Another useful maven plugin is the Tidy plugin. It will reformat and reposition the elements in your POM against the maven specification as they should be. The command is as follows:

mvn tidy:pom

Check which class is loaded from which jar

Sometimes you have classloading issues and you don’t know which class from which jar is loaded. Here’s a useful trick that will print every class from which jar is loaded. First you need to export the MAVEN_OPTS environment variable to pass the -verbose:class to the jvm:

export MAVEN_OPTS="-verbose:class"

after that all you have to do is run the compiler and grep for your class:

mvn clean install | grep my.class

This particular solution will solve your compile-time problems, but it can also be used for runtime check too.