Published on

Debugging Maven Plugins


Today I was trying to use a Maven plugin that was misbehaving. I tried the usual things like add debug and error logging using the -X and -e flags respectively but still had no luck. I then tried to see if I could add the sources for the plugin as a library in IntelliJ. I managed to find the sources using the library search tool searching using the form groupId:artifactId:version and IntelliJ added it but complained about having more than one source root so I cancelled the operation.

In the end I cloned the project and added it to the one I was trying to debug the plugin in:

  • Go to Maven Projects
  • Then click the green plus
  • Choose the pom file from the root directory where you cloned the plugin source code

Right, now I had the sources but still had to workout how to run the plugin in debug mode. Maven jobs in IntelliJ can be run in debug mode by clicking the little bug icon, so I tried modifying the goals to rather be the plugin I wanted but this did not run in debug mode as I would have expected.

After Googling a bit I found 2 ways to do this:

The easiest

  • Open the Maven Projects panel
  • Expand the plugins section
  • Find the plugin you want, right click it and choose Debug

The other option if your IDE does not have this is

  • Setup a remote configuration
  • Use port 8000 and host localhost
  • Make sure the debugger is set to attach
  • Use the socket transport option
  • Then run your plugin using mvnDebug yourplugin
  • So for example if you normally run mvn yourPlugin you just swap mvn for mvnDebug then quickly click run for your remote configuration

Whichever option you choose if you put breakpoints anywhere in the plugin source code you will hit those breakpoints.