Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

multi project - Gradle exclude a specific subproject from full build


In our Gradle project, we want to add a new module for functional-tests that needs to be able to access dependencies from other subprojects but still not be run as part of the full project build. If I try this, it still gets built:

def javaProjects() {
   return subprojects.findAll { it.name != 'functional-tests' }
}

configure(javaProjects()) {
   ...
}

project(':functional-tests') {
    ....
}

The result is the same even if I move the functional-tests build to a separate build.gradle file of its own. Can someone point out how to achieve this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found a better solution to be to exclude the functional tests from running on the command line or via the build file.

For example, to run all tests except the functional tests, run:

$ gradle check -x :functional-tests:check

Then when building the project, you can let the subproject build but exclude their tests from running.

$ gradle clean assemble -x :functional-tests:check

A better option is do disable the functional tests in your build file unless a property is set. For example, in your build.gradle you'd add:

project('functional-tests') {
    test {
        onlyIf {
            project.hasProperty("functionalTests")
        }
    }
}

This way, functional tests are always skipped unless you specify a specific build property:

$ gradle check
$ gradle -PfunctionalTests check

Hope that helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...