Tip #15: How To Debug Unit Tests During Maven Builds
By ByronNevins on Apr 12, 2012
It must be really really hard to step through unit tests in a debugger during a maven build. Right?
Here is how i do it:
1) Set up these environmental variables:
MAVEN_OPTS=-Xmx1024m -Xms256m -XX:MaxPermSize=512m
MAVEN_OPTS_DEBUG=-Xmx1024m -Xms256m -XX:MaxPermSize=512m -Xdebug (no line break here!!) -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999
MAVEN_OPTS_REG=-Xmx1024m -Xms256m -XX:MaxPermSize=512m
2) create 2 scripts or aliases like so:
To debug do this:
- run maveny.bat
- run mvn install
- attach your debugger to port 9999 (set breakpoints of course)
- When maven gets to the unit test phase it will hit your breakpoint and wait for you.
When done debugging simply run mavenn.bat
- If you set the suspend=n flag then you can just leave it -- but only one maven build can run at a time because of the debug port conflict.