Skip to content

neelkamath/gradle-debug-bug

Repository files navigation

Gradle Debug Bug

This project demonstrates a bug in Gradle which causes it to be unable to debug Java 9+ projects.

From the docs:

org.gradle.debug=(true,false)

When set to true, Gradle will run the build with remote debugging enabled, listening on port 5005. Note that this is the equivalent of adding -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 to the JVM command line and will suspend the virtual machine until a debugger is attached. Default is false.

Gradle allows for remote debugging by running gradle --debug-jvm. The --debug-jvm flag instructs Gradle to supply the JVM with -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005. From Java 9 onwards, the argument is supposed to be -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 (reference). This is why remote debugging Java 9+ projects with Gradle's --debug-jvm doesn't work.

Installation

Install Docker so that we can easily simulate the required environments.

Usage

  1. We'll first run the Java 9+ project to see that the debugger doesn't work.
    1. Start the debugger.
    2. It will fail with the error java.io.IOException: handshake failed - connection prematurally closed.
  2. Now we'll modify the project to show that it works in Java 8.
    1. Change line 10 of build.gradle.kts from sourceCompatibility = JavaVersion.VERSION_13 to sourceCompatibility = JavaVersion.VERSION_1_8
    2. Change line 4 of docker-compose.yml from image: gradle:6.4.0-jdk14 to image: gradle:6.4.0-jdk8.
    3. Start the debugger.
    4. The debugging session starts successfully.

License

This project is under the MIT License.

About

Demo of Gradle unable to remote debug Java 9+ projects

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published