I have two Gradle projects, let's call them Blue and Green. Green depends on Blue, as declared in its build.gradle
:
repositories {
mavenLocal()
}
dependencies {
compile 'org.example:blue:1.0'
}
Blue uses the Maven plugin to build the appropriate artifact:
apply plugin: 'maven'
group = 'org.example'
version = '1.0'
If I run the install
task on Blue, it creates a JAR and a POM and puts them in my ~/.m2/repository
, no problem.
I import Blue's build.gradle
into my IDEA project, and it creates a module for Blue, again no problem.
If I now import Green's build.gradle
into my IDEA project, it creates a module for Green, picks up the Mavenized version of Blue from the repository, creates a corresponding library, and adds the Blue library to the Green module as a dependency.
However, if I now make a code change in Blue, that code change isn't picked up in Green. Green is going to continue to use the now-stale copy from the Maven repository. The only way to get the Blue changes is to re-install Blue, and as for refactoring something in Blue and having the refactoring cover the usages in Green, forget about it. Problem.
How can I get IDEA to recognize the interdependencies between my Gradle projects and their corresponding IDEA modules?
Edited to add: Multi-module isn't really an option because the dependencies in question are shared between multiple application projects (not to mention other shared-library projects) and don't fit neatly into a single hierarchical directory structure.
Edited to add: For a pointer to what I eventually came up with, see this answer. It still requires manually creating multi-module projects when you want to work on both a project and its dependencies, but it lets you swap source and binary dependencies in and out more or less freely.
Discovered the following workaround:
After importing Green's build.gradle
, open Module Settings for the Green module (or select it under Project Structure). Then, on the Dependencies tab, manually add the 'live' dependencies and move them above the Gradle versions in the list:
This will persist even through a "Refresh external project" on Green's build.gradle
, which is helpful when you're editing it to add third-party libraries etc.
Note that you can delete the Gradle versions (Gradle: blue-2.0-snapshot
etc.), but they'll get re-added when you refresh the project.
Also worth noting: This will let you live-edit and refactor Blue, Yellow, and Green together, but if you need to do a Gradle build for any reason (e.g. if you're using Gradle's jettyRun
task to launch a webapp), you'll need to make sure you Gradle-install
Blue and Yellow, because (as long as we're not talking about a multi-module project) Gradle is only ever going to use the canned versions from the repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With