views:

134

answers:

3

Hi all,

Is there any way to actually debug a maven plugin while it is in action. What i mean is that for example we have the maven-clean-plugin. So when this plugin executes it's action can we somehow debug and check inside the source code of maven-clean-plugin?

Obviously we would have to associate the java source for the plugin in eclipse but how can we set it for debugging?

Thanks.

EDIT: Changing the subject I'm sorry guys may be i should have been more precise. Actually i have my web-app which is a maven project, which makes use of 3rd party maven plugins. Now when i do a mvn clean install i need to debug my 3rd party maven plugin. Now in my maven dependency i dont get a dependency to that plugin jar, which is quite normal. Any ideas?

+2  A: 

This might be slightly off, since I'm going to talk about IntelliJ IDEA. With IDEA, you can load a maven project directly, and then simply right click on one of the build lifecycle phases (clean, package, install etc...) and choose debug. The IDE then runs that phase with the correct classpath and drops you into a debugger.

I've used the debugger to debug several of my own plugins. I've never tried debugging a third party plugin, although I imagine this will be relatively painless if the jar still has debug symbols in it and you have corresponding source code.

The community edition of IDEA is available for no fee.

mdma
I've done the same thing more or less in Eclipse for my own plugins.
tschaible
Is there any links you could provide me with regards to eclipse?
You can find the two "big" Maven plugins for Eclipse on http://maven.apache.org/eclipse-plugin.html
jhominal
Thanks. But this is related to the m2eclipse that we commonly use rt. I believe this doesnt have any info reg debuggin. Anyway ill try googling more intensively
+2  A: 

If you want to debug Maven execution in eclipse, here is how I did it, with mostly command-line tools (no Eclipse plugin used) (may be off at some points, I haven't done that for 6 months):

  • Run, from the command line, mvndebug in place of the mvn command. Maven will begin launching and wait for an external debugger to appear on a TCP port before resuming. Note the port number.
  • Configure in Eclipse a custom, remote debug configuration. (See http://www.ibm.com/developerworks/library/os-ecbug/ , Remote debugging) - set the port number as the one used by mvndebug. Also put the source files that you will be using for debugging in the Debug configuration.
  • Launch the remote debug configuration. Maven should resume and you will catch bugs in Eclipse.
jhominal
Could you please see my post. I've updated it.
+3  A: 

If you are using Eclipse with the m2eclipse plugin, simply launch your build with Debug As... instead of Run as....

If you are not using m2eclipse, run mvnDebug instead of mvn (for Maven 2.0.8+) and attach a remote debugger on port 8000. For Maven 2.0.8<, add the remote debuggin options to the start script.

Of course, you need to import the sources of the plugin in your workspace.

See also

Pascal Thivent
Could you please see my post. I've updated it.
@user320550: do you have the sources of the plugin in your workspace? If no, try it.
Pascal Thivent
Actually this is what i tried. I have my maven project setup in my workspace. Also i have set up a maven plugin project which has the source of the plugin. Now i go to the pom.xml location of my maven project and execute mvndebug install. It gives me the port as 8000. Now i right clicked on my maven project and selected remote debugging and chose port 8000. In the sources tab i added the maven plugin project as the source lookup path and clicked remote debug. I have put breakpoints in my plugin java files. Now in my cmd it simply it seems to be stuck and doing nothing..
@user320550: *it simply it seems to be stuck and doing nothing* didn't you actually hit the breakpoint?
Pascal Thivent
Thanks for your help Pascal. It hits my breakpoint now, however it takes close to a minute to hit it.