Archive for the ‘maven’ tag
Reading time: < 1 minute
I previously wrote about useful debugging techniques with maven. Our maven builds have become complex, with Branch By Abstraction, and about 40 devs working simultaneously on the codebase in 2 continents. We have at least 3 profiles for each of the branch abstractions that are currently running in the codebase. I’m one of the tech leads, and in order to keep the team’s build consistent and easy to remember, we have a wrapper script (thanks to Cosmin).
Here it is:
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.
Reading time: 1 – 2 minutes
Working on os x with Spaces means I want to read something on another space instead of waiting idly for a 50 second build. But, I don’t want to get distracted. So, I use Growl and growlnotify for notifications of the build’s completion.
#!/bin/sh # this file is called: mvn (and is executable, and added to path before actual mvn command) # capture all args passed in to forward to real mvn ARGS=$* # We need the client's specific settings.xml, so always specify it now /usr/bin/mvn -s /Volumes/TrueCryptClient/opt/maven/conf/settings.xml $ARGS # when you have growlnotify installed and on your path, this will pop it up # when the build is done growlnotify -m "DONE: maven $ARGS"
Note: if you get this error from growlnotify: could not find local GrowlApplicationBridgePathway, falling back to NSDNC, it probably means growl is not started. Start up growl in your System Preferences.
Update: Thanks Cosmin, for the enhancement. Use this snipped in the script. Have an environmental variable for what the notify command is. And say what the build status is in the growl notify.:
if [[ -n $NOTIFY ]]; then ($command && $NOTIFY "Build Complete" && exit 0) || ($NOTIFY "Build Failed" && exit 127) else $command fi