Make one source set dependent on another

2019-04-18 07:12发布

I have an integration test source set in gradle, and it is dependent on my main classes being compiled. I set that up by doing

integrationTestClasses.dependsOn 'classes'

Is this the way to do it, or is there a way to setup dependencies on source sets so this happens automatically? In my configurations block I already have

integrationTestCompile { extendsFrom testCompile }
integrationTestRuntime { extendsFrom integrationTestCompile, testRuntime }

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-04-18 07:19

What's missing is:

dependencies {
    integrationTestCompile sourceSets.main.output
}

With this in place, task dependencies should be established automatically.

查看更多
Anthone
3楼-- · 2019-04-18 07:37

It is also possible to establish the dependency chain when defining the sourceSets. This worked to setup the "main" sourceSet to depend on a "generated" sourceSet:

// Default sourceSets already created by the java plugin: src/main and src/test
// Default content for each sourceSet: /java and /resources
sourceSets {
    // Adding src/generated
    generated
    // Setting src/main to depend on the dependencies and output of src/generated
    main {
        compileClasspath += generated.compileClasspath + generated.output
    }
}

The same principle should work to setup "integrationTest" to depend on "main".

查看更多
登录 后发表回答