Multiple Maven Modules - Find usage doesn't work
Hi,
We have multiple separate Maven projects. I am trying to open all of them as a single project so that I can work on them and use navigation, refactoring, find usage, etc..
I have all the projects I need in one directory. I created a new Empty Project in IntelliJ. I then go to Project Structure and under Modules add a few of the projects in the directory.
Consider:
ProjectA.ClassA uses ProjectB.ClassB.MethodB.
I try to navigate from ClassA to MethodB. IntelliJ opens read-only ClassB from the dependencies of ClassA rather than the one from the project Modules.
I can then Choose Sources at the top of the editor window, and point to the project on my hard drive. Navigation then works as expected. However, if I try to do Find Usage from ClassB on methodB, nothing is found (even if the scope is All Places).
Am I missing something?
I'm new to this team, and the way their projects are setup seems a bit strange, and I suspect might be the cause of the problem, but I'm not sure:
Project B is not a direct dependency of ProjectA. In fact, A depends on B through two other projects.
The dependencies are versioned, but the dependency versions do not coincide (e.g. A depends on B-0.1.2, but B's version in the pom is 0.0.1). Not very familiar with Maven, but IntelliJ seems to be able to make sense of it, so the poms are valid
Finally, some projects (A for example) actually have nested Modules where the implementation is (e.g. ProjectA has Module1[something random], and Module2[actual implementation - I'm trying to navigate from here, and it's where the usage of B is]).
Hopefully this makes some sense. Any help would be appreciated!
Please sign in to leave a comment.
Please check http://books.sonatype.com/mvnex-book/reference/multimodule.html.
I'd define the parent pom.xml and specify the child modules inside, then you can import the single parent pom in IntelliJ IDEA and everything should be configured automatically.
Dependencies in pom.xml should correspond to the actual module dependencies that you have the sources for, otherwise IntelliJ IDEA will resolve them from the Maven repository using the binary dependencies (jars), this way find usages/navigation will not work between the modules and you will be navigated inside the binary dependency instead.
Thanks very much for your response, Serge.
I did try having a parent pom with modules defined inside, but it still doesn't work. The difference with the example in the link you provided, is that all my projects are separate and don't share a parent; and while I can create one (and have), I don't want to (can't) modify each project to point to this parent.
I suspect that your second point is closer to the problem, though; however I'm not sure I understand what you mean by "Dependencies in pom.xml should correspond to the actual module dependencies".
For instance, ProjectA defines a dependency on B as follows:
The parent pom defines modules such as:
Although the above is an extreme oversimplification.
This is very close to the working example, with the exception of linking to parent pom in the modules, and the sub-modules.
I guess what I'm most confused about it why I'm able to navigate from A to B (go to implementation) after choosing the correct source manually, but not able to find the usage of B (find usage).
Thanks again.
It would help to understand your specific problem if you could share some dummy sample project illustrating the issue with the find usages.
I sorted it out by changing the versions in all the poms to coincide. Thanks so much for the help, and sorry for the stupid question :p