4
votes

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?

2

2 Answers

4
votes

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

0
votes

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.