6

I'm developing a project using Vert.X framework using Gradle build tool. The problem I have is that breakpoints in IntelliJ simply doesn't work in any way I've tried.

Here is a run configuration for Vert.X which I use in Gradle:

run {
    args = [
            'run', mainVerticleName,
            "-conf", confPath,
            "--redeploy=$project.ext.watchForChange",
            "--launcher-class=$mainClassName",
            "--on-redeploy=$project.ext.doOnChange"
    ]
}

So the deployment is done using Gradle, runs without any issues, IntelliJ debugger is connected, but breakpoints are not working.

The ways I've tried to make it work:

1) Gradle run configuration. Here is a run configuration for Intellij IDEA: Intellij Run Configuration using Gradle

Tried to use a Remote debugging tool, started application with the following VM options:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000

But this didn't work.

2) Application configuration: IntelliJ Run Configuration using Application

In this case I just can't start the project as I get the following message on the startup:

Error: Could not find or load main class io.vertx.core.Launcher

Vert.X Core library is in the classpath and configuration seems to be correct, so can't get were is the problem.

The source code of the project is public and can be found on GitHub:

vertx-gradle-architecture-starter

Vert.X version - 3.4.0. Gradle version - 3.4.1. IntelliJ IDEA version - 2016.3.5. OS - MacOS Sierra 10.12.3.

Interesting fact is when I deploy Vert.X from tests - breakpoints work. Any ideas why breakpoints doesn't work in cases I've described above?

yyunikov
  • 5,719
  • 2
  • 43
  • 78
  • At least your second option should definitely work! Which version of vert.x are you using? Maybe it's an older version that doesn't have `io.vertx.core.Launcher`? – MirceaG Mar 10 '17 at 10:56
  • It's `io.vertx.core.Launcher` as you can see in screenshot. I get the message `Error: Could not find or load main class io.vertx.core.Launcher` on startup of this configuration, so can't event check the debugger. And I have `vertx-core` in my dependencies. – yyunikov Mar 10 '17 at 10:59
  • Sorry, I didn't saw you specified you're using 3.4.0. I got your GitHub project and tried locally with the configuration from the screenshot. It works! Try to clean/rebuild the project in Intellij. – MirceaG Mar 10 '17 at 11:15
  • @MirceaG that's surprising. Which configuration you've used? – yyunikov Mar 10 '17 at 11:26
  • Rebuilding, cleaning, reimporting just cloned project - nothing helped. – yyunikov Mar 10 '17 at 12:01
  • 1
    Application configuration - 2. It's exactly like in your screenshot. [see screenshot](http://tinypic.com/view.php?pic=3sg2p&s=9). I have no other hints, sorry :-( – MirceaG Mar 10 '17 at 12:48
  • @MirceaG Thanks, actually your screenshot was very useful as I've noticed that you have `api` module instead of `api_main` in you run configuration. See my answer below. – yyunikov Mar 10 '17 at 16:10
  • Issue 2) [is caused by this](http://stackoverflow.com/a/42588061/104891). – CrazyCoder Mar 10 '17 at 21:27
  • @CrazyCoder thanks. Any idea why 1st one doesn't work? – yyunikov Mar 11 '17 at 06:00
  • 3
    It doesn't work because there are 2 JVMs started, one with the launcher is started with the debug options, then it spawns another JVM with the application code and it's not running in debug mode, debugger is connected to the first VM where there is no code corresponding to your breakpoints, since it runs in the second VM. Check your process tree. There should be a way to specify VM options for the spawned VM (via `args`), then you will be able to use Remote debug for it. – CrazyCoder Mar 11 '17 at 06:10
  • @CrazyCoder thanks a lot of explanation, I was able to attach Remote debug for spawned VM with adding Java options. See my updated answer. – yyunikov Mar 11 '17 at 09:43

2 Answers2

7

Here are solutions to both issues. Thanks to @CrazyCoder for help on this.

1) run command is run in separate VM. So, to make it work, I've added --java-opts argument to the script:

run {
    args = [
            'run', mainVerticleName,
            "-conf", confPath,
            "--redeploy=$project.ext.watchForChange",
            "--launcher-class=$mainClassName",
            "--on-redeploy=$project.ext.doOnChange",
            // used for attaching remote debugger
            "--java-opts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000"
    ]
}

This allows to attach Remote debug configuration on port 8000.

2) By default, Intellij IDEA creates separate modules per source sets, so I had source sets for api_main and api_test modules. After turning off this feature - Application debug run started to work.

This can be turned off in Gradle Settings. Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle: uncheck create separate modules per source set.

enter image description here

This is an IntelliJ IDEA issue - reference.

Community
  • 1
  • 1
yyunikov
  • 5,719
  • 2
  • 43
  • 78
  • Without "create separate module per source root" and when having more than src/main (for instance src/integrationTest) you will have it wrong then - IntelliJ won't know the configuration for that module (classpath and so on) – kboom Aug 10 '17 at 12:55
3

I had the exact same issue and following worked for me. redeploy, launcher and on-redeploy options are not necessary in intelliJ. if we remove those the debug works after application is up.

run {
    args = [
        'run', mainVerticleName,
        "-conf", confPath
    ]
}
Kishore Tulsiani
  • 1,106
  • 13
  • 29