Way1 :
- Open Project Structure (either Ctrl+Alt+Shift+S or File > Project Structure)
- Select "Modules" on the far left under Project Settings
- Select the module in question in the middle pane
- 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.
- Right click on any directory in your IntelliJ project, select "Mark Directory As...", and choose "Source Root".
- That director folder will change color from yellow to blue; IntelliJ considers all those directories to be in your CLASSPATH.