Archive for the ‘troubleshooting’ tag
Reading time: 3 – 5 minutes
We’re (stuck*) using maven on a project, and this means often the build doesn’t act like you’re expecting. Debugging requires knowledge about maven’s capabilities and less documented features. Here are some tips, please add more in the comments.
-Xflag shows debug logging, and tee it to a file which you then search for clues of what happened. This is great for verifying if a plugin actually ran, and what it did. Example:
mvn -X install | tee out.txt
mvn dependency:tree(show the transitive dependencies of your dependencies) 
-Dtest=MyJavaTest(just use the name of the class, no package necessary)
mvn help:system(show environmental variables and system properties) 
mvn help:active-profiles(show the active profiles to be run)
mvn help:all-profiles(show all profiles maven reads)
mvn help:effective-pom(show the logical pom.xml being used)
mvn help:effective-settings(show the logical settings.xml which is being used)
mvn help:describe -DgroupId=org.apache.maven.plugins -DartifactId=maven-resources-plugin -Ddetail(show details about a plugin’s options)
-DskipTeststhis will skip running tests, but still compile it. or
-Dmaven.test.skip=truewhich will skip compilation and execution of tests (use with judgment, I believe in testing)
-Xdoesn’t show you the properties when you needed them, you can also use the ant-run plugin to echo a property value (does anyone else know a better way to do this in maven? Tell me what a property value is at the time of the plugin or goal executing?)
- Run your tests paused in debug mode, waiting for a debugger to attach to port 5005 with mvn -Dmaven.surefire.debug test 
-  http://maven.apache.org/plugins/maven-dependency-plugin/
-  http://maven.apache.org/plugins/maven-help-plugin/
-  http://cvs.peopleware.be/training/maven/maven2/debuggingPom.html
-  http://maven.apache.org/plugins/maven-surefire-plugin/examples/debugging.html
- Personal experience
*Note: Initially I disliked the confusion and long, slow learning curve with maven. After working 8 months with maven and my colleagues Lucas Ward and Paul Hammant, I’m feeling much more comfortable and am generally okay with it. For small open source work, where you want a project quickly, but don’t want to spend a few hours with ant, I like it very much. For our large project, maven is fundamentally broken. Too much file copying is required, and manual intervention on a complex build is impossible, or extremely tedious. Running with our own build script we control could be dramatically more flexible.
On a mailing list Paul recently recommended a few other to consider:
Maven Dependency plugin
- shows me the transitive deps (say, “how the hell is MX4J being dragged into the build ?”)
- show me unused, but declared dependencies.
There’s a ton of free capability to that plugin – http://maven.apache.org/plugins/maven-dependency-plugin/
An Atlassian dependency plugin
Atlassian wrote a plugin ( http://confluence.atlassian.com/display/DEV/FedEx+XI+-+Keeping+track+of+you+maven+dependencies ) that guards against undesired changing dependencies.
Maven Enforcer Plugin
A more intrusive way of guarding against deps that, say, should not make it into a war. http://maven.apache.org/plugins/maven-enforcer-plugin/
What tips do you have? Please share them in the comments.