Compile Problems

I have a project with an unusual structure. I have module1 and module2. Module1 has a dependency on Jar1. The sources for Jar1 is the source directory of Module2. Once I attach the source to Jar1, Module2 can no longer compile. The classes in Module 2 don't recognize other classes in the same package. If I remove the source attachment, everything goes back to normal.

Basically, I have this strange structure because Module1 code depends on the compiled classes of Module2 but Module1 cannot have any of Module2 libraries in it's classpath. This works fine in Eclipse, but I don't really want to use Eclipse.

Is this a bug or is there something else I can do to get this working?

I am using 7.0M2.

Any help would be appreciated.


Try making Module2 dependent on Module1.

I would probably create a module just for Jar1. Then make Module1 and
Module2 dependent on ModuleJar1.


Thanks for the suggestions! I really can't have module2 dependent on module1, it would cause all kinds of classpath problems and there really is no dependency in that direction. Also, I simplified the scenario quite a bit to help describe the situation. I tried the second suggestion of putting Jar1 in a module but if there is any module in the project that has Jar1 as a dependency and uses Modue2 as the source, Module2 will no longer compile. Good suggestion though. thanks.


I'm not sure i understand your setup, it seems your "jar1" is the built artefact for module 2 from what you describe. Is this correct ?
If it is correct, does this mean your module2 contains the sources for jar 1 AND some other sources ? would it be acceptable in this case to split your module 2 in 2 ? 1 for the jar 1 sources and 1 for the remaining sources ?


You are correct that Jar1 is the compiled output of module2. In fact, it doesn't have to be a jar, I could also use the module2 output dir as my dependency for module1. Ideally I would just have module1 depend on module2. The problem is, the libraries from module2 make module1 tests fail, etc. In order to keep module2 libraries out of my module1 classpath at runtime, I have to depend on module2's compiled output and the source of that dependency needs to be module2 source code. Splitting module2 doesn't change the situation. IDEA can't seem to handle this at all and for now I've had to switch back to Eclipse.


you should be able to not export the libraries of module 2 , and should get rid of the problem with this.
In the module settings for module 2, go to the dependencies tab, and uncheck the export checkboxes for the libraries you want to get rid of.
Another possibility would be, in module 1 dependencies tab, to put your module 2 at the bottom of the list, this should make sure your own dependencies will be used instead of module 2's ones when there is an ambiguity


I don't quite understand your scenario but I think I've seen something similar.

Module A
Module B
Module C

Global Library X (sources are Module A)

If Module B is dependent on Module A
and Module C is dependent on Global Library X (built from A)
then in B and C all references to A will be red.

If I switch Module C to be dependent on A instead of X the problem goes away.



I am not exporting libraries from module2 but its jars are still getting in the classpath of module1 and messing everything up. putting the libs at the bottom doesn't help because module2 libs are implementing some low-level stuff and getting picked up regardless.


I think you have it, but 3 modules aren't necessary for this example. Module A depends on Module B's output. Module A can't depend on Module B directly because of runtime classpath issues. Trying to add indirection by adding Module C doesn't change the end behavior of IDEA.