5

I'm trying to run a task in debug mode and have it stop in breakpoints but it doesn't seem to work. The task executes normally but the IDE gives me a socket error:

Error running MyProject [myTask]: Unable to open debugger port (127.0.0.1:52550): java.net.SocketException

Note that the port it tries to use changes on every try. I thought of adding something to VM Options: in the task configuration but I have no idea what.

PentaKon
  • 4,139
  • 5
  • 43
  • 80
  • Does this help you? http://stackoverflow.com/questions/17179886/using-intellij-to-set-breakpoints-in-gradle-project – Dropout Dec 14 '15 at 13:26
  • No. I'm new to gradle/groovy and I'm not really sure on how to implement the solution provided. Do I have to declare a new task called `run`? I tried adding `run { debug true }` for example but it gives me an exception `Could not find method run()...` – PentaKon Dec 14 '15 at 14:42
  • Since you're using IntelliJ, the instructions in the question here may help you out: http://stackoverflow.com/questions/33816953/how-to-debug-play-2-application-built-with-gradle - note that you can't really debug build.gradle files. – Eric Wendelin Dec 14 '15 at 19:28
  • An alternative: Use the Gradle Tool window _(Shift)(Shift)_ and type Gradle and run the debug through that UI. That seems to work for me with most projects out-of-the-box – Eric Wendelin Dec 14 '15 at 19:29
  • 1
    That's exactly my problem. When I right-click on a gradle task and try to debug it it just runs without stopping on breakpoints (either in the build script or in the .groovy classes). – PentaKon Dec 15 '15 at 07:49

2 Answers2

2

I had a similar issue to this, but I could not even build with gradle as it would give me "Unable to open debugger port (127.0.0.1:xxxxx):" when it got to a certain sub-project

What I found was a special character used in a char char degreeSymbol = '°'; that was causing something to crash and that's why it was unable to open the debugger port.

There is a gradle task called "test" under the verification folder that will find this issue and show you exactly where it is.

In IntelliJ community edition 2016.2 you can find this by going to View > Tool Windows > Gradle. Then expand the name of your project (root) > tasks > verification.

To fix the issue either change the special character to a unicode string final String DEGREE = "\u00b0"; or in your root gradle.build do:

apply plugin: 'java'
compileJava { options.encoding = "UTF-8" }

or if you have multiple sub-projects:

allprojects {
    apply plugin: 'java'
    compileJava { options.encoding = "UTF-8" }
}
willbush
  • 190
  • 4
  • 5
0

Create a new run configuration. Choose 'Application' as the configuration type (i.e. not 'Gradle'). Then choose the main class to run. IntelliJ will first run gradle as usual, and run the chosen class in debug mode. I am not sure if there are any limitations as I just found this solution myself.