6

Inspired by https://stackoverflow.com/a/14853683/286795, I'm trying to remotely debug a Maven project using mvnDebug and IntelliJ. However, the execution doesn't stop on my breakpoints. To reproduce a simple Hello World example:

On the local machine:

git clone https://github.com/LableOrg/java-maven-junit-helloworld.git
cd java-maven-junit-helloworld
mvnDebug test

On the remote machine:

  1. Open IntelliJ
  2. Check out from Version Control->Git, set URL: https://github.com/LableOrg/java-maven-junit-helloworld.git, Clone
  3. Open the project
  4. Open Hello.java, set a breakpoint at the line that says printer.println(HELLO);

  5. Run->Debug...->Edit Configurations..., Add New Configuration->Remote

  6. Set Debugger mode: Attach, Transport: Socket, Host:, Port:8000
  7. Apply, Debug

The tests will now run WITHOUT stopping at the breakpoint. Why?

matthiash
  • 3,105
  • 3
  • 23
  • 34

2 Answers2

11

While running the mvnDebug command, use -DforkMode=never.

so your maven command will look like this:

mvnDebug -DforkMode=never -Dmaven.surefire.debug clean install

For more info on -DforkMode=never, read here

Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54
Sadaf Rasool
  • 111
  • 1
  • 5
2

You need to set debugForkedMode of maven-surefire-plugin to true

 <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <version>${maven-surefire-plugin.version}</version>
   <configuration>
      <debugForkedProcess>true</debugForkedProcess>
   </configuration>
 </plugin>

Then add another remote debug configuration on port 5005.

amseager
  • 5,795
  • 4
  • 24
  • 47
  • Hi @amseager, Thank for the help. It works for me ! I have another question. Why I need to start 2 remote debug : 1 on port 5005 and another on 8000 ? – Hieu Lam Nov 13 '19 at 08:07
  • 1
    Hi. These are default ports for maven surefire plugin and mvnDebug respectively. Actually, I found it easier not to use mvnDebug but simply mvn (f.e. "mvn test" or via "test" goal in IDEA's maven toolbar). In that case you only need to start remote debug on port 5005 (but "debugForkedProcess" flag should be set to true anyway). Works for maven 3.6.1, dunno about older versions. – amseager Nov 13 '19 at 10:41