# Problems debugging plugin code in debugger

**URL:** <https://discuss.gradle.org/t/problems-debugging-plugin-code-in-debugger/6964>\
**Category:** Old Forum Archive\
**Created:** [March 10, 2015, 4:35pm UTC](https://discuss.gradle.org/t/problems-debugging-plugin-code-in-debugger/6964 "2015-03-10T16:35:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Karr](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/david_karr/32/145_2.png) [@David\_Karr](https://discuss.gradle.org/u/David_Karr)\
**Post date:** [March 10, 2015, 4:35pm UTC](https://discuss.gradle.org/t/problems-debugging-plugin-code-in-debugger/6964/1 "2015-03-10T16:35:00Z")

</div>

I’m working on my first plugin, getting testing and debugging working before I write a lot of code. The plugin and tasks are working skeletons, and a separate project applying the plugin reports the task on “gradle tasks”, so that looks good so far.

I now want to step through the existing plugin code in the debugger. The advice on this seem scattered. The user guide has almost no information about this, and I think I see a discrepancy in what little is there. The only statement in the entire user guide that mentions debugger support is the following section:

> 23.13.2. Debugging \> The test task provides a Test.getDebug() property that can be set to launch to make the JVM wait for a \> debugger to attach to port 5005 before proceeding with test execution. \> This can also be enabled at invocation time via the --debug-jvm task option (since Gradle 1.12).

When I run Gradle 2.3 with “–debug-jvm”, it says: “Unknown command-line option ‘–debug-jvm’.”

I also found a [Gradle forum post](http://forums.gradle.org/gradle/topics/how_do_you_attach_a_debugger_to_gradle_so_that_i_can_debug_it_running_a_task) that Peter responded to. I’m using that as a guide, but I’m still seeing weird results with no success.

I first turned off the daemon in ~/.gradle/gradle.properties and then killed the daemon process.

I set a breakpoint in my plugin’s “apply” method. I know it’s getting here because I just added a line that fixes a bug, and after installing the plugin the project using it doesn’t get the error anymore.

In my shell, I set GRADLE\_OPTS to:

```gradle
"-Dhttp.proxyHost=myproxyhost -Dhttp.proxyPort=myproxyport -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5006"

```

I then ran the following, with the following output:

```gradle
% gradle tasks --no-daemon -Dorg.gradle.debug=true
Listening for transport dt_socket at address: 5006
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: http://gradle.org/docs/2.3/userguide/gradle_daemon.html.

```

The statement about forking the JVM is curious.

I then connected to 5006 from Eclipse.

At this point both Gradle and Eclipse are contentedly waiting for something to happen.

What can I do here?

---

<div class="post-metadata">

**Author:** ![Mark\_Viera](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_viera/32/1543_2.png) [@Mark\_Viera](https://discuss.gradle.org/u/Mark_Viera)\
**Post date:** [March 10, 2015, 7:04pm UTC](https://discuss.gradle.org/t/problems-debugging-plugin-code-in-debugger/6964/2 "2015-03-10T19:04:00Z")

</div>

You don’t want to specify both GRADLE\_OPTS and ‘-Dorg.gradle.debug=true’. Simply adding the command line property is enough, and will start listening on port 5005. Also, you don’t necessarily need to disable to the build daemon. If you don’t the command line option will debug the build daemon JVM, which is what you want. Also, one advantage of debugging the daemon is you don’t have to continually reattach to the debug process, since the daemon is persistent across multiple builds.

---

<div class="post-metadata">

**Author:** ![David\_Karr](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/david_karr/32/145_2.png) [@David\_Karr](https://discuss.gradle.org/u/David_Karr)\
**Post date:** [March 10, 2015, 7:34pm UTC](https://discuss.gradle.org/t/problems-debugging-plugin-code-in-debugger/6964/3 "2015-03-10T19:34:00Z")

</div>

Perfect. Thanks.

---

<div class="post-metadata">

**Author:** ![David\_Karr](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/david_karr/32/145_2.png) [@David\_Karr](https://discuss.gradle.org/u/David_Karr)\
**Post date:** [March 11, 2015, 4:04pm UTC](https://discuss.gradle.org/t/problems-debugging-plugin-code-in-debugger/6964/4 "2015-03-11T16:04:00Z")

</div>

Has there been any thought of making this a standard command-line argument, so someone doesn’t have to remember this property when they have to do this?

Also, is the port number overriddable? I don’t need to, but I would imagine someone eventually will want that.

---

<div class="post-metadata">

**Author:** ![Mark\_Viera](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_viera/32/1543_2.png) [@Mark\_Viera](https://discuss.gradle.org/u/Mark_Viera)\
**Post date:** [March 11, 2015, 4:47pm UTC](https://discuss.gradle.org/t/problems-debugging-plugin-code-in-debugger/6964/5 "2015-03-11T16:47:00Z")

</div>

The port isn’t overridable via the ‘org.gradle.debug’ property however you could specify whatever debug arguments you wanted with the ‘GRADLE\_OPTS’ environment variable.

---

<div class="post-metadata">

**Author:** ![David\_Karr](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/david_karr/32/145_2.png) [@David\_Karr](https://discuss.gradle.org/u/David_Karr)\
**Post date:** [March 11, 2015, 5:09pm UTC](https://discuss.gradle.org/t/problems-debugging-plugin-code-in-debugger/6964/6 "2015-03-11T17:09:00Z")

</div>

Is this functionality technically supported yet? A year ago, Peter said it was not: [http://forums.gradle.org/gradle/topics/how\_do\_you\_attach\_a\_debugger\_to\_gradle\_so\_that\_i\_can\_debug\_it\_running\_a\_task](http://forums.gradle.org/gradle/topics/how_do_you_attach_a_debugger_to_gradle_so_that_i_can_debug_it_running_a_task) .

So you’re saying that setting “org.gradle.debug=true” sets some default “-Xdebug” arguments, and whatever goes in GRADLE\_OPTS will override it?

---

<div class="post-metadata">

**Author:** ![Mark\_Viera](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_viera/32/1543_2.png) [@Mark\_Viera](https://discuss.gradle.org/u/Mark_Viera)\
**Post date:** [March 11, 2015, 5:17pm UTC](https://discuss.gradle.org/t/problems-debugging-plugin-code-in-debugger/6964/7 "2015-03-11T17:17:00Z")

</div>

I’m not certain that is the case. My suggestion is that if you don’t want to use the default port you should use ‘GRADLE\_OPTS’ **instead** , rather than defining both.
