Tip #15: How To Debug Unit Tests During Maven Builds

Posted by ByronNevins on Oracle Blogs See other posts from Oracle Blogs or by ByronNevins
Published on Thu, 12 Apr 2012 18:36:21 -0500 Indexed on 2012/04/13 5:37 UTC
Read the original article Hit count: 284

Filed under:

It must be really really hard to step through unit tests in a debugger during a maven build.  Right?

Wrong!

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:

 maveny.bat:

set MAVEN_OPTS=%MAVEN_OPTS_DEBUG%

mavenn.bat:

set MAVEN_OPTS=%MAVEN_OPTS_REG%

 


 To debug do this:

  1. run maveny.bat
  2. run mvn install
  3. attach your debugger to port 9999 (set breakpoints of course)
  4. When maven gets to the unit test phase it will hit your breakpoint and wait for you.

When done debugging simply run mavenn.bat

Notes

  1. If it takes a while to do the build then you don't really need to set the suspend=y flag.
  2. 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.



© Oracle Blogs or respective owner

Related posts about /Sun