Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij IDEA editor: classpath order

I've tried to search for a solution for this, but have had no joy: In Intellij IDEA 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?

EDIT: I'm using the latest Intellij 11.

EDIT: for anyone finding this question, these troubles went away in Intellij 12+

like image 308
tridian Avatar asked Dec 12 '11 19:12

tridian


1 Answers

I had this problem and was using Vladimir's answer which worked (hence my upvote) but unfortunately I found that I had to keep re-editing the .iml file as it was constantly being rewritten. After some digging I found how to change this permanently:

Navigate to File -> Project Structure -> Modules -> -> Dependencies tab

IntelliJ will add the dependencies to the classpath in the order they are listed there. To move them, simply highlight the dependency you want to move and use the up and down arrows on the toolbar at the bottom.

like image 176
Tom McIntyre Avatar answered Oct 06 '22 00:10

Tom McIntyre