Make one source set dependent on another

大憨熊 提交于 2019-12-21 06:58:48

问题


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 }

回答1:


What's missing is:

dependencies {
    integrationTestCompile sourceSets.main.output
}

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




回答2:


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".



来源:https://stackoverflow.com/questions/18140471/make-one-source-set-dependent-on-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!