Intellij IDEA editor: classpath order

I've tried to search for a solution for this, but have had no  joy: In Intellij IDEA 11 I've set up a set of modules so that I have the  following:

  • My Web Project (all module dependencies set to 'Runtime')
  • My Web Project Dependency #1 (+ artifact that copies JAR to MWP's /WEB-INF/lib)
  • My Web Project Dependency #2 (+ artifact that copies JAR to MWP's /WEB-INF/lib)


Dependency#1 has a class org.acme.foo, but so does MWP and the  definition differs (oh joy). It builds ok - all code in MWP correctly  builds against the classes in MWP instead of Dependency#1.

But...in its editor, Intellij is giving me the red squiggle because  it's preferring to reference the class in Dependency#1 with its  incompatible definition.

Ignoring the fact that there really shouldn't be this class/package  clash, can anyone help me push Intellij into looking at the class in the  local module, and not at the class in the dependency?

Thanks,
Trystan

4 comments

You did not mention how your project is configured (that is, is it an IDEA project, a Maven project, a Gradle project, etc.) But in most cases, you should be able to solve the issue by changing the order the dependencies are listed in the module definition.

  1. Open Project Structure (either Ctrl+Alt+Shift+S or File > Project Structure)
  2. Select "Modules" on the far left under "Project Settings
  3. Select the module in question in the middle pane
  4. Arrange the order of the dependencies lists. One of the dependencies will be <Module Source> Which ever is listed first will be the one IDEA will give preference to. So if you want the local instance of Foo to be used, make sure <Module Source> is above the dependency.


Hopefully that will solve the issue. IDEA usually defaults to having the Module Source listed prior to any dependencies. So I'm not sure if that is your issue.

screenshot.png

0

Hi. Thanks for your reply. It's a plain Java project. The two dependencies are just Java classes compiled into a JAR, and the main web project is just set to compile a bunch of Java classes to the WEB-INF/classes directory. All pretty boring and straightforward.

I double-checked the modue setup and the order was correct: the web project module sources are top of the list (under the JDK), with the dependency at the bottom.

As an experiment I removed the "dependency #1" module as a dependency...and added it as a compiled JAR library: Now I don't get the errors as before (the classes in the web project correctly prefer the other classes in the web project), but for solitary classes in Dependency #1, I can only cmd-click through to the definitions from the attached source of the JAR....rather than the source of "dependency #1"'s module.

It's obviously not ideal! Do you know why the compile/reference order in the module setup would apply to JAR libraries but not to dependencies?

Many thanks,
Trystan

0

Looks like it is this bug: http://youtrack.jetbrains.net/issue/IDEA-78828.

--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0

That's reassuring, thanks. It's been holding me back from upgrading so at least I know it should get fixed.

0

Please sign in to leave a comment.