Neither IntelliJ nor Eclipse plugin are able to resolve dependencies using default strategy

I have one simple project with two modules and master. I can build it with Gradle and dependencies report shows all proper data. Yet when I’m importing the project into IntelliJ or Eclipse, it does not compile.

Here’s what I see in Eclipse and in IntelliJ:

Expected foo -> 4.1.3 bar -> 4.2.1

Actual foo -> 4.1.3 bar -> 4.1.3

While I understand, that this issue cannot be addressed directly to Gradle, I would like to mention, that both, Eclipse STS and IntelliJ Gradle plugin do not recognize 4.2.1 version as the proper one. Which makes me think that either those plugins are not using tooling kit properly or there’s something wrong with the tooling kit. Any ideas?

master _build.gradle

subprojects {
    apply plugin: 'java'
    repositories {
        mavenCentral()
    }
}

master _settings.gradle

includeFlat 'foo', 'bar'

foo _build.gradle

dependencies {
    compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.1.3'
}

bar _build.gradle

dependencies {
    compile project(':foo')
    compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.2.1'
}

_src/main/java/HelloWorld.java

import org.apache.http.util.EntityUtils;
  public class HelloWorld {
    public static void main(String[] args) throws Exception {
        EntityUtils.consumeQuietly(null);
    }
}

EntityUtils.consumeQuietly() is the method introduced in 4.2 of httpcore.

Here’s the output from gradle:

andrey-mbp:bar andrey$ gradle dependencies :bar:dependencies

------------------------------------------------------------ Project :bar ------------------------------------------------------------

archives - Configuration for archive artifacts. No dependencies

compile - Classpath for compiling the main sources. ±-- master:foo:unspecified |

— org.apache.httpcomponents:httpcore:4.1.3 -> 4.2.1 — org.apache.httpcomponents:httpcore:4.2.1

default - Configuration for default artifacts. ±-- master:foo:unspecified |

— org.apache.httpcomponents:httpcore:4.1.3 -> 4.2.1 — org.apache.httpcomponents:httpcore:4.2.1

runtime - Classpath for running the compiled main classes. ±-- master:foo:unspecified |

— org.apache.httpcomponents:httpcore:4.1.3 -> 4.2.1 — org.apache.httpcomponents:httpcore:4.2.1

testCompile - Classpath for compiling the test sources. ±-- master:foo:unspecified |

— org.apache.httpcomponents:httpcore:4.1.3 -> 4.2.1 — org.apache.httpcomponents:httpcore:4.2.1

testRuntime - Classpath for running the compiled test classes. ±-- master:foo:unspecified |

— org.apache.httpcomponents:httpcore:4.1.3 -> 4.2.1 — org.apache.httpcomponents:httpcore:4.2.1

(*) - dependencies omitted (listed previously)

BUILD SUCCESSFUL

Total time: 1.115 secs

1 Like

Related discussion with IDEA guys: http://youtrack.jetbrains.com/issue/IDEA-99640

Post on STS forum: http://forum.springsource.org/showthread.php?134326-Gradle-plugin-does-not-resolve-dependencies-using-default-strategy

Thanks for reporting this problem!

I’d say it’s a bug in Gradle. I would expect the generated IDEA configuration (with tooling api or with command line) to match the Gradle command line behavior (e.g. the actual classpath).

The scenario is not quite realistic because in reality one would have a consistent version of httpcomponents within the same multi-project. However, I realize that the scenario posted here is probably oversimplified for clarity.

I’ll create a ticket for it in Jira and provide workarounds.

Created ticket here: http://issues.gradle.org/browse/GRADLE-2652