kotlindebuggingintellij-ideamaven-3

Intellij CE Debug Can't Connect


Unable to debug a JUnit test in latest IntelliJ Community Edition v2024.2. The test builds and runs successfully.

But trying to debug it fails. It appears IntelliJ CE can't connect to the JVM the test runs in.

ERROR: transport error 202: connect failed: Operation timed out ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510) JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [open/src/jdk.jdwp.agent/share/native/libjdwp/debugInit.c:700]

Details about my IntelliJ CE

IntelliJ IDEA 2024.2 (Community Edition) Build #IC-242.20224.300, built on August 7, 2024 Runtime version: 21.0.3+13-b509.4 aarch64 (JCEF 122.1.9) VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Kotlin: 242.20224.300-IJ

Details about my MacBook, JDK, and Kotlin:

  • macOS 14.3.1
  • OpenJDK 22.0.2
  • Kotlin 1.9.24 (also fails with 2.0.10)

I don't think I ever saw this error before from IntelliJ. Also don't remember needing to manually configure IntelliJ to debug a local unit test.

Just for the heck of it, I fully removed then re-installed the latest IntelliJ CE. I also upgraded to the latest OpenJDK and removed older JDKs.

Anyone know why I can't debug with this setup?

Here's my Maven pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>hey.you</groupId>
    <artifactId>foo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <kotlin.version>1.9.24</kotlin.version>
        <junit.version>4.13.1</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
            <version>${kotlin.version}</version>
        </dependency>

        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test-junit</artifactId>
            <version>${kotlin.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src/main/kotlin</sourceDirectory>
        <testSourceDirectory>src/test/kotlin</testSourceDirectory>

        <plugins>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${kotlin.version}</version>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Startup command Intellij generates to run the test in debug mode.
NOTE: Intellij picks a random debug port each time debug run requested.

/Users/bob/_tools/jdk/bin/java 
-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:58502,suspend=y,server=n 
-ea 
-Didea.test.cyclic.buffer.size=1048576 
-javaagent:/Users/bob/Library/Caches/JetBrains/IdeaIC2024.2/captureAgent/debugger-agent.jar 
-Dkotlinx.coroutines.debug.enable.creation.stack.trace=false 
-Ddebugger.agent.enable.coroutines=true 
-Dfile.encoding=UTF-8 
-Dsun.stdout.encoding=UTF-8 
-Dsun.stderr.encoding=UTF-8 
-ideVersion5 
-classpath /Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA CE.app/Contents/plugins/junit/lib/junit5-rt.jar:/Applications/IntelliJ IDEA CE.app/Contents/plugins/junit/lib/junit-rt.jar:/Users/bob/_dev/mkv_exp/target/test-classes:/Users/bob/_dev/mkv_exp/target/classes:/Users/bob/.m2/repository/com/fasterxml/jackson/module/jackson-module-kotlin/2.14.2/jackson-module-kotlin-2.14.2.jar:/Users/bob/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.14.2/jackson-databind-2.14.2.jar:/Users/bob/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.14.2/jackson-core-2.14.2.jar:/Users/bob/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.14.2/jackson-annotations-2.14.2.jar:/Users/bob/.m2/repository/org/jetbrains/kotlin/kotlin-reflect/1.5.32/kotlin-reflect-1.5.32.jar:/Users/bob/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/2.0.10/kotlin-stdlib-2.0.10.jar:/Users/bob/.m2/repository/org/jetbrains/annotations/13.0/annotations-13.0.jar:/Users/bob/.m2/repository/org/jetbrains/kotlin/kotlin-test-junit/2.0.10/kotlin-test-junit-2.0.10.jar:/Users/bob/.m2/repository/org/jetbrains/kotlin/kotlin-test/2.0.10/kotlin-test-2.0.10.jar:/Users/bob/.m2/repository/junit/junit/4.13.1/junit-4.13.1.jar:/Users/bob/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar com.intellij.rt.junit.JUnitStarter 
-junit4 foo.HelloTest

Solution

  • As of Aug 2024, with any recent version of Kotlin, Idea CE, Maven, and JDK I can only debug Kotlin remotely by manually using Maven & a custom Idea Remote Debug run-config. Here's how:

    First, launch Maven surefire plugin in debug mode:

    mvn -Dmaven.surefire.debug test

    It waits for a remote debug connection on default port 5005.

    Next, launch this run-config to connect with the unit test's JVM. It'll stop at the first break point.

    enter image description here


    This is the first time I seriously tried using Idea CE. So far, it's been disappointing :-(

    Is it possible JetBrains cripples Idea CE to force a paid upgrade to Idea Ultimate? Idea CE is portrayed as a viable, extensible Open Source editor (comparable to VSCode). That's not what I'm finding so far.