20

I'm working on multiple Gradle projects with internal and external dependencies, and so far I am happy that thanks to Gradle's dependency management I can modify a library project without affecting every application that uses the library.

When I need to modify a library project and test it using an application project that uses it, I need to do the following,

  • Modify the library project and commit to SCM
  • Trigger CI to build the library project and push it to my Gradle repository
  • Update the application project's build.properties to refer to the new version of library project
  • Iterate the above steps until everything works and there is no bug

So it became quite combersome now. Can I configure IntelliJ IDEA so that

  • All my Gradle projects are in one window, like the screenshot below, which is Twitter's Finagle imported using its pom.xml. Sadly IntelliJ's JetGradle plugin doesn't seem to understand Gradle subprojects.

Finagle subprojects

  • When build.properties's dependencies are my subprojects, read dependency from local snapshot, otherwise download them from the Gradle repository

Thanks.

lyomi
  • 4,230
  • 6
  • 30
  • 39
  • This looks like a multi-module Maven project, which is the same as a multi-project Gradle build. Do you have a single multi-project build, or multiple separate builds? – Peter Niederwieser Jul 30 '13 at 09:05
  • Currently I have multiple separate builds, but I can group them together as a single multi-project build (using Gradle subprojects), if I can open all projects in one IntelliJ window like above. I just don't know how to make IntelliJ work well with Gradle subprojects, just like it does with multi-module Maven projects. – lyomi Jul 31 '13 at 06:25

2 Answers2

23

If you want to open all projects in a single IDEA window, you'll have to aggregate them into a multi-project build, at least until IDEA 13 hits the market. Before IDEA 13, it's better to use Gradle's IDEA integration. Once you have a multi-project build, all you need to do is to add allprojects { apply plugin: "idea" } to the root build script, run gradle (cleanIdea) idea, then open the generated IDEA project.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • I could open all projects in one window but apparently JetGradle doesn't like it this way... but thank you very much for the info! – lyomi Aug 08 '13 at 06:40
  • @PeterNiederwieser How does IDEA 13 fix this? I'm using 13 and not having any better luck. – David Moles Apr 21 '14 at 04:10
  • Last time I checked, there was a button in the Gradle tool window to import another Gradle build into the same IDEA project. – Peter Niederwieser Apr 21 '14 at 05:37
  • I can't find the button. It's strange to me that this feature doesn't work better in intelliJ. It relies on auto-import suggestion being triggered automatically, but the window doesn't always appear and changes in gradle files are not reflected immediately. I really prefer the way projects can be synced in Android Studio, with a simple button. – Snicolas Nov 23 '14 at 15:46
  • Even with IntelliJ 2017.1, it still doesn't work as good as the good old maven. I have 2 gradle projects, each with multi module. The first project depends on the second project. What happen is that the first project resolve the dependency through the second project JAR created by Jenkins, not by resolving it locally. – Wins Mar 31 '17 at 04:32
13

Currently in IntelliJ IDEA 2019.2 you can add the gradle subprojects like so

  1. Open Gradle Tool Window via View > Tool Windows > Gradle menu
  2. Click on "Link Gradle Project" button (the plus sign)Link Gradle Project button
  3. Select the build.gradle file corresponding to the subproject
  4. Go to File > Project Structure > Modules > NameOfSubproject
  5. Navigate to main/java and click on Mark as: Sources enter image description here
  6. Mark the main/resources as Resources
  7. Restart IntelliJ IDEA

The sources of the subproject will be recognized by IntelliJ and you can use Navigate Class action for the classes in the subproject

RubenLaguna
  • 21,435
  • 13
  • 113
  • 151