Is it possible to prevent Maven from auto-populating source roots from other modules?

Answered

We use org.codehaus.mojo:build-helper-maven-plugin to add test sources and resources from one module to another (add-test-source and add-test-resource goals from that plugin). The reason for this is somewhat complicated but it boils down to the fact that we have a set of test cases in module A, that need to run in modules B and C (which each have different sets of dependencies).

However, this seems to not play well with IntelliJ. Because the same source root can't appear in more than one module, each of these ends up under either B or C (continuing the example above), seemingly at random. This causes more issues when trying to run these tests directly in the IDE (ex: the test class under A appears to be in a B src/test/java source root, for example).

Is anyone else using this plugin and figured out the best way to manage things in IntelliJ?  IntelliJ IDEA Ultimate 2019.1 on OS X.  Thank you.

0
2 comments

Shared source directories between modules are not supported by IDE indeed. The workaround would be to create one more module with the dependencies configured as needed. Another option to consider is to use Maven profiles to switch between additional source directories. Another possible solution is to temporarily exclude other modules from the project or have them opened in a separate IDE project.

0
Avatar
Permanently deleted user

Thanks for the confirmation, Andrey.  I will work on refactoring things to avoid this kind of structure.

0

Please sign in to leave a comment.