Saturday, March 7, 2015

How to debug a Maven plugin

Maven plugins are debugged using the Java remote debugging mechanism. By using mvnDebug instead of mvn, a remote debugging session is started. It can be started by triggering a complete build or by invoking a specific goal, in both cases, over a project that uses the plugin. 

Lets exemplify with the plugin built in the previous post. By executing the goal check-properties with mvnDebug, the execution will hang saying it is listening on a specific port:


mvnDebug org.softwaredistilled:properties-maven-plugin:1.0:check-properties -Dcheck="i18n_??"

Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000



Another option would be to trigger a build like:

mvnDebug clean package

Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000



Most of Java IDEs, if not all of them, provide some remote debugging tools. In Eclipse, a Remote Java Application debug configuration has to be created (Debug configuration section) that once started, it will stop at any break point.

The tricky part is that the plugin must be installed every time a modification is performed in order to see the changes at debugging time.

No comments:

Post a Comment