Huj
Huj

Reputation: 51

Use IntelliJ to debug a Gradle Execute Task

I have the following Gradle task:

task execute(type:JavaExec, dependsOn:['build']) {
    main = 'com.something.Main'
    classpath = sourceSets.main.runtimeClasspath
}

When I debug the task in IntelliJ I get the following error:

ERROR: transport error 202: connect failed: Connection refused
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]
:execute FAILED

Upvotes: 5

Views: 2357

Answers (2)

Mario
Mario

Reputation: 1801

It seems later versions of IntelliJ Idea cannot connect debuggers to forked test runners when using the Gradle Test runner.

In your sources root, add a gradle.properties file with the next two lines:

maxTestForks = 1
testForkEvery = 0

That should do the job.

Upvotes: 2

Kirby
Kirby

Reputation: 15875

I had a very similar problem. When I was invoking Gradle in IntelliJ, the Java environment by default contained

JAVA_OPTS=-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:59842,suspend=y,server=n

I removed the JAVA_OPTS from the environment all together and voila, no more JDWP error because no more JDWP.

Upvotes: 0

Related Questions