Adam
Adam

Reputation: 10036

Do source set compile tasks automatically depend on the normal compileJava task? Gradle

Does the compileJava task from the Gradle java plugin depend on the compileSourceSetJava task of any source sets I've created? Or do I need to manually use dependsOn to make sure all source sets are compiled when I run compileJava?va`?

Upvotes: 0

Views: 1258

Answers (1)

MartinTeeVarga
MartinTeeVarga

Reputation: 10898

I believe it doesn't automatically depend on anything. If you just create an empty source set, it's just that - a set of sources. But depends on your use case, there might be an implicit dependency. Consider the following gradle script:

apply plugin: "java"

sourceSets {
    integrationTest {
        java {
            compileClasspath += main.output
            runtimeClasspath += main.output
        }
    }
}

configurations {
    integrationTestCompile.extendsFrom testCompile
    integrationTestRuntime.extendsFrom testRuntime
}

task integrationTest(type: Test) {
    testClassesDir = project.sourceSets.integrationTest.output.classesDir
    classpath = project.sourceSets.integrationTest.runtimeClasspath
}

Because the integrationTest source set references the main java source set, gradle automatically creates a dependency on compileJava (and processResources).

So the answer is "it depends" (pun not intended). There might be implicit dependencies based on how have you defined the source sets and configurations. However if you don't define any relation between the two source sets, there is no reason why would they automatically create any dependencies.


BTW There is a nice gradle plugin for generating task graphs if you would like to explore that more.

Upvotes: 1

Related Questions