Pure Danger Tech


navigation
home

The Maven tip file

25 Feb 2009

This is a raw dump of some random Maven tips that I use to debug things that come up with Maven. Instead of stashing these away in a text file I thought maybe someone else could find some use in them.

Debugging Maven Two of the most important command-line options for debugging Maven issues are -e and -X. -e will turn on full exception stack traces if you are seeing an error. Perhaps more useful, -X will turn on Maven debug logging and dump a lot more output about how things are being resolved, full command lines of launched processes, and many other useful tidbits of information to help you get to the bottom of an issue.

Dependencies Maven is famously known for managing dependencies for your project. But it can’t do this without your help – you need to be fully aware what things you depend on both directly (in your pom), indirectly (through parent poms), and transitively (behind the others). The most essential tool in your arsenal here is the dependency plugin.

There are a bunch of useful goals on the plugin but the one I use constantly is mvn dependency:tree. This will show you a tree of all your dependencies, and transitively their dependencies.

Often you’ll find you depend on some other project and the dependencies of that project are screwed up, usually by depending on stuff as a compile-time dependency that really should be “runtime” or “provided” scope. You’ll want to investigate dependency exclusions which let you cut off those nasty transitive dependencies.

The dependency:analyze goal is also pretty useful in tracking which of those dependencies aren’t needed at all.

If you’re using the m2eclipse plugin (and if you’re using Eclipse, you absolutely should be), it actually will show you graphs of the dependencies of your project and their transitive dependencies, including the ability to filter different scopes, etc. Good stuff.

Pom analysis I find the help plugin to be pretty helpful at understanding how poms and parent poms interact to define your project. In particular, I find help:effective-pom, help:effective-settings, help:active-profiles and help:all-profiles all come in handy.

Debugging tests One option I use frequently to skip unit tests altogether is -Dmaven.test.skip=true.

An essential option to know is how to debug a unit test run from Maven with -Dmaven.surefire.debug. This will spawn the test and wait for you to connect with a remote debugger. If you use m2eclipse, it can simplify this a great deal, letting you debug a test more directly.

Hope those help someone…