Maven vs. Gradle lib dependency substitution in the IDE

I’m a new user but not really a new user. I lost the old password and email and had to create a new account.

Anyway, given I’ve the following projects:

parent
--- common
--- child1 (depends on common)

unrelated (depends on common)

When both parent and unrelated are Maven projects and opened in the same IDE workspace (I verified in IDEA but I’m told that Eclipse behavior is the same), I can navigate from unrelated to common without having to link sources. Refactoring anything in common correctly finds references of it in unrelated. Since Maven doesn’t differentiate between submodule and lib dependencies, both dependencies shown above are declared in the same manner.

With Gradle, unrelated doesn’t seem to know that common exists in the same workspace. Refactoring anything in common breaks unrelated. The source code is only linked within submodules, as in between child1 and common.

I’m looking at Gradle docs 23.8.3.3. Conditionally substituting a dependency,

configurations.all {
    resolutionStrategy.dependencySubstitution.all { DependencySubstitution dependency ->
        if (dependency.requested instanceof ModuleComponentSelector && dependency.requested.group == "org.example") {
            def targetProject = findProject(":${dependency.requested.module}")
            if (targetProject != null) {
                dependency.useTarget targetProject
            }
        }
    }
}

However this only seems to work if the requested module is a subproject, which seems pointless, because if it were a subproject, we’d use a project dependency anyway, not a lib dependency.

Any idea how can I get the Maven like behavior in Gradle? Someone asked this in the IDEA forum where he was told to create his own custom plugin. IDEA claimed that this feature is coming in 2016.3 version but they lied. https://youtrack.jetbrains.com/issue/IDEA-114469

Using Gradle 3.0, the latest. For full disclosure, I’ve also posted this question on StackOverflow.

The gradle team is currently working on supporting that scenario, which we call “composite builds”. Composite builds allow you run multiple separate builds as if they’re one big gradle build and substitute the dependencies as you have described it. Idea is relying on that functionality. As you’ve seen in the ticket, it is “reopened”. I don’t have insights on idea development but the following thread describes in detail how this gradle core feature is initially supported by buildship, the official gradle plugin for eclipse: Exciting new Buildship Features coming up

Just exanding a bit on René’s answer: You will be able to import composites (new in Gradle 3.1) into the IDE with Gradle 3.2. Binary dependencies will be substituted for project/module dependencies in Eclipse/Idea.

2 questions:

  1. Is there a release plan somewhere that shows when each version is planned to be released and whether or not you’re on target? I ask this because there’s plan and then there’s reality.
  2. Is there a sample composite build project available that I can look at? I see lot of talk on this feature online but so far haven’t come across a single working project.