16

I'm switching to Intellij and trying to do the same thing as in Eclipse. In Eclipse, you can add a project as a dependency in another project (project properties -> "Java Build Path" -> "Projects" -> Click on my library project).

The current situation is that I'm developing a library and I can test the features in another project without building the jar file every time I add new stuff to the library.

I'm trying to achieve this with Intellij but without success (the projects are both imported in Intellij).

How can I do that?

user2336315
  • 15,697
  • 10
  • 46
  • 64
  • Maybe https://www.jetbrains.com/pycharm/help/project-dependencies.html can help you. – Mihai8 Mar 04 '15 at 21:39
  • Did you get this working as reading above help link didn't solve my issue. I've shifted to IDEA from Eclipse today :) – vikramvi May 29 '17 at 10:45
  • couldn't get it working https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000322004-Adding-Project-Dependancy-is-not-working. I thought IDEA is better than Eclipse and it's turning out that hard to learn and buggy as well – vikramvi Jun 26 '17 at 10:48

3 Answers3

7

File > Project Structure. Then choose your module, and add any dependency, either Jar, Library or Module:

IntelliJ Screenshot

Larger image here: https://i.stack.imgur.com/Mr7V7.png

acanby
  • 2,936
  • 24
  • 26
  • .. well maybe I'm doing something wrong; but I can only see my current project in the list that displays the modules. – user2336315 Mar 05 '15 at 12:26
  • Hmm now, I created a module from the "library" project. Ok I got this working, but is it compulsory to create a module from the other "library" project? – user2336315 Mar 05 '15 at 12:29
  • That doesn't work. Yes I can use the library project in mine; but if I add a method or something else, I can't see it in my test project. Any ideas? – user2336315 Mar 05 '15 at 12:43
  • Could try just adding the directory where the other code is. Not the nicest thing, but it might work.... – acanby Mar 05 '15 at 21:52
  • 2
    This is what I did but it doesnt work either.. I really need this feature. I can't believe its not possible with Intellij but with Eclipse. There's must be a solution... – user2336315 Mar 09 '15 at 15:41
  • @acanby it's not working for me, can you please check https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000322004-Adding-Project-Dependancy-is-not-working and let me known what may be going wrong ? – vikramvi Jun 26 '17 at 10:47
  • I noticed that if I do this with Eclipse, I can use files in the dependency test directory from the dependent project. With IntelliJ I can only use those in main. I am using a Maven project structure, and I know that by design those test files aren't getting built into the jar for the dependency, so that may be related. I was using Eclipse as my workaround so IntelliJ's behavior doesn't help me. – k-den Jul 13 '17 at 19:18
  • I got this working. Just make sure that when you're adding dependencies you're adding it to your main/test directory and not on the root project name. Wasted an hour of my life :) – Toofy Mar 06 '19 at 17:10
4

From File -> project structure, select Modules. You will be presented with all the added projects. Click a project and from the right hand side select Dependencies tab. This will show you projects that are not imported in red coloured text. HTH

0

File > Project Structure > Project Settings > Modules

Project Structure

  1. Add the module you want to add as dependency.
  2. Add your module dependency in your project.

If you use Maven you'll see the following message:

Module 'your-module' is imported from Maven. Any changes made in its configuration may be lost after reimporting.

→ Add your project to your pom.xml

If you don't do that, your dependency will be removed each time you reimport/refresh maven projects.

Emeric
  • 6,315
  • 2
  • 41
  • 54