PentaKon
PentaKon

Reputation: 4636

Debug gradle task in IntelliJ

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.

Upvotes: 6

Views: 7866

Answers (2)

ModestMiceAndMen
ModestMiceAndMen

Reputation: 21

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.

Upvotes: 0

willbush
willbush

Reputation: 320

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" }
}

Upvotes: 2

Related Questions