How to debug a maven goal with intellij idea?

Intellij Idea

Intellij Idea Problem Overview


Can you debug a maven goal with Intellij IDEA? I know that I can right-click and run Debug. However, the maven plugin does not appear in my External Libraries list, so I can not go into the code and set a breakpoint. Thus, Debug runs through the goals without stopping, like Run does.

I am using OS X 10.8 and IDEA 12.0.2.

EDIT: Goal

I've written custom specRunner for https://github.com/searls/jasmine-maven-plugin - However, $specs$ stays empty. So I try to see which files are actually loaded.

Intellij Idea Solutions


Solution 1 - Intellij Idea

Figured it out:

  1. from the command line, run maven goal with mvnDebug instead of mvn. E.g. mvnDebug clean
  2. Open the source of the maven plugin you want to debug in intelliJ and set a breakPoint
  3. In IDEA, add a Remote JVM Debug Configuration.
    1. Under Settings, set Transport: Socket, Debugger Mode: Attach, Host: localhost, Port: 8000 (default port of mvnDebug).
  4. Run the Configuration in Debug mode. It should connect to the waiting mvnDebug jvm.

Solution 2 - Intellij Idea

Very easy. I am using Intellj Idea 15.0.4

  1. Set the breakpoint in your maven plugin
  2. In the tag "Maven Projects" go to the project witch is using your maven plugin.
  3. In "Plugins" find your plugin and over the goal right click and Debug

Here is a screenshot:

screenshot

Solution 3 - Intellij Idea

Old question, but I was having the same need and it took me a while to get it to work. Hopefully can help someone.

For test debugging use:

mvn <goal> -Dmaven.surefire.debug

or

mvn <goal> -Dmaven.failsafe.debug

When execution stops and listens to socket at address 5005 (default) you run your configured remote debugger.

How to configure it:

Run -> Edit configurations -> Remote Transport: socket Debugger mode: Attach Port: 5005 (default)

-> Save.

Solution 4 - Intellij Idea

The easiest way to debug maven goal ONLY within IntelliJ is to create a regular maven goal and in the runner tab pass those VM options:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000

Where 8000 is a port number for remote debugging.

Maven goal configuration

Then create new Remote configuration with port 8000. Run this configuration after running maven goal.

Remote debugging configuration

Solution 5 - Intellij Idea

I think the easiest solution is to temporarily add the maven plugin as a dependency. Once this is done, IntelliJ will treat this just like any other dependency and you can set breakpoints the usual way.

Solution 6 - Intellij Idea

No need to setup up Java Remote Debugger or anything like that. It is literally just a right click -> debug on the Maven goal now, as explained in the official docs.

Solution 7 - Intellij Idea

Either You can refer to above answer Or just add this plugin to pom.xml

           <plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<configuration>
			<jvmArguments>
			-Xdebug - 
            Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
			</jvmArguments>
			</configuration>
		</plugin>

And run maven goal with mvn instead of mvnDebug. E.g. mvn spring-boot:run

In IDEA, add a Remote Configuration. Under Settings, set Transport: Socket, Debugger Mode: Attach, Host: localhost, Port: 8000 (default port of mvnDebug).

Run as Debug in IDEA , whenever you want to debug the code.

Solution 8 - Intellij Idea

Since you are working with Intellij, there is already a built-in debugger there and you do not need to necessarily use mvnDebug which is a command line tool. Check out this tutorial: How to Debug Maven Applications in Intellij IDEA.

The tutorial uses the Maven Exec Plugin and lets you debug the application without a need to use the command line or MvnDebug. Thought sharing it might be of value here.

Solution 9 - Intellij Idea

@Peter Szanto 's answer work for me, but I don't like mess my source code.

And I can't make those MvnDebug way work.

So I try another way, add plugin source as IDEA module.

Here is the detail step:

  1. Clone the plugin source as an independent project.

  2. In your project, go to File -> New -> Module from Exist Sources and add the plugin project you clone in step 1.

  3. Now you can open the plugin source code and set some break point.

  4. Run your maven goal as debug mode, it should stop at the break point.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrwengView Question on Stackoverflow
Solution 1 - Intellij IdearwengView Answer on Stackoverflow
Solution 2 - Intellij IdeagorumsView Answer on Stackoverflow
Solution 3 - Intellij IdeavilkgView Answer on Stackoverflow
Solution 4 - Intellij IdeaMichał StochmalView Answer on Stackoverflow
Solution 5 - Intellij IdeaPeter SzantoView Answer on Stackoverflow
Solution 6 - Intellij IdeaandrasView Answer on Stackoverflow
Solution 7 - Intellij Ideaabhishek ringsiaView Answer on Stackoverflow
Solution 8 - Intellij IdeaambodiView Answer on Stackoverflow
Solution 9 - Intellij IdeaminView Answer on Stackoverflow