Custom source set dependencies are not added to allprojects dependencies


(Renat) #1

Hi, I have a project with a submodule. In the root build.gradle I define compile dependencies for all projects using allprojects. Then in the same file I define custom source set accTest with its own dependencies. When I import this in eclipse I get compilation errors for classes in accTest because the additional dependencies are not included in the classpath.

Here is my build.gradle

allprojects {
    apply plugin: 'java'

    repositories {
        mavenCentral()
    }

    dependencies {
        compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'
    }
}

sourceSets {
    accTest 
}

dependencies {
    accTestCompile group: 'com.google.guava', name: 'guava', version: '19.0'
    accTestCompile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'
}

task wrapper(type: Wrapper) {
    gradleVersion = '3.0'
}

Steps to reproduce:
in Eclipse File/Import/Gradle Project import root project, nested module will be imported automatically

Expected behavior: Class ATest is compilable.

Actual behavior: Class ATest is not compilable (com.google.common.collect.ImmutableMap not found).

Everything works fine if you run from CLI however:

$ gradle wrapper
$ ./gradlew build accTest

Eclipse version: Neon Release (4.6.0)
Buildship version: 1.0.18.v20160817-1550
Gradle version: 3.0

Here is relevant output of $ ./gradlew dependencies

:dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

accTestCompile - Dependencies for source set 'acc test'.
+--- com.google.guava:guava:19.0
\--- org.slf4j:slf4j-api:1.7.21

accTestCompileClasspath - Compile classpath for source set 'acc test'.
+--- com.google.guava:guava:19.0
\--- org.slf4j:slf4j-api:1.7.21

accTestCompileOnly - Compile dependencies for source set 'acc test'.
+--- com.google.guava:guava:19.0
\--- org.slf4j:slf4j-api:1.7.21

accTestRuntime - Runtime dependencies for source set 'acc test'.
+--- com.google.guava:guava:19.0
\--- org.slf4j:slf4j-api:1.7.21
...

Source can be found here https://github.com/rzhilkibaev/eclipse-gradle-problem
Any ideas?


(Stefan Oehme) #2

You have to add your custom configuration to the Eclipse classpath.

eclipse.classpath.plusConfigurations << configurations.accTestRuntime

(Renat) #3

Thank you Stefan! It worked.