I have a (Maven-based) project A loaded in Intellij that has a number of dependencies.
I have the source files of one of those dependencies (say B) in another Intellij project.
I would like to put breakpoints in B and debug project A so that A stops when breakpoints are reached in project B.
In Eclipse, I just need to have both projects in the same workspace and it works. Since there are no workspaces in Intellij, I wonder how to do it, and if it is possible.
To do this, go to Settings/Preferences | Build, Execution, Deployment | Debugger and select Drag to the editor or click with middle mouse button. Clicking a breakpoint will then enable or disable it.
If you want to go to next break point press F8. Save this answer.
To continue the program execution after it has been suspended, press F9 or select Run | Debugging Actions | Resume from the main menu.
The other answers sound like they would work, but all I had to do was go to:
Project Structure (Ctrl+Alt+Shift+S)
> Modules
> on the Sources tab for the module that has dependencies, look on the right side,
click the + Add Content Root, then add the src
folder of the dependency project.
I was able to then put breakpoints in those src
files and IntelliJ would step to them in debugging.
(Note you may see the warning "Alternative source available for the class ...
")
Reference
From https://www.jetbrains.com/help/idea/creating-and-managing-modules.html,
"Modules normally have one content root. You can add more content roots. For example, this might be useful if pieces of your code are stored in different locations on your computer."
When working with multiple maven projects, I find it convenient to put both under a parent maven project. The two child projects are not aware of the parent and remain independent of each other, but by aggregating them on one parent pom, you can conveniently build and test them at the same time, keeping the dependent in sync with its dependency. When you do that, you can also create Run configurations for each project, launch them in debug mode, and put breakpoints in either or both of them.
The parent pom stays in the parent folder of both projects, and does not need to go into source control because the child poms don't refer to it as their parent--its only for your convenience in working on both at the same time. Such a pom might look like:
<?xml version="1.0" encoding="UTF-8"?>
<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>anything</groupId>
<artifactId>anything</artifactId>
<version>0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>All projects</name>
<modules>
<module>project-1-subdirectory</module>
<module>project-2-subdirectory</module>
</modules>
</project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With