'Debug Java gradle task in IntelliJ for Apple Silicon

I work on a multi module Java project using Gradle as the build tool. I recently upgraded my hardware to Apple Silicon and downloaded the Apple Silicon IntelliJ (currently using 2022.1, but also had the same problem on the first silicon version). However, when running gradle tasks in debug mode I can't manage to get it to stop at breakpoints. Also, after stopping the process from IntelliJ, the actual java process is still running in the background (I get port already used errors on rerun and have to stop the previous one from Activity Monitor).

My project structure is as following:

baseModule
|- module-a
|  |- submodule a1
|  |- submodule a2
|- module-b
|  |- submodule b1
...and so on

In the baseModule I have run tasks defined for each module in the build.gradle:

task run_a {
    dependsOn gradle.includedBuild("module-a").task(":myTask")
}

In module-a in the build.gradle I have the following:

if (findProperty("propName")) {
    apply from: "propName.gradle"
}
...
<and other tasks defined>

My propName.gradle is:

def startingPoint = "com.x.Application"

task myTask (type: JavaExec) {
    description = "Run module A"
    classpath = sourceSets.main.runtimeClasspath
    main = startingPoint
    args = ['development']
}

When I run the run_a task in the Silicon IntelliJ, debugging doesn't work and I have hanging processes after terminating the task. When I run using a older Intel based IntelliJ, I have no issues.

Any suggestions on how to fix this issue? I can debug fine in the Silicon version if I add the task from propName.gradle directly in the build.gradle of module-a and run it from there directly as a separate task, without using the run_a task defined in the baseModule.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source