Gradle从完整构建中排除特定的子项目 [英] Gradle exclude a specific subproject from full build

查看:1577
本文介绍了Gradle从完整构建中排除特定的子项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在我们的Gradle项目中,我们想为功能测试添加一个新模块,它需要能够访问其他子项目的依赖项,但仍不能作为完整项目构建的一部分运行。如果我尝试这样做,它仍然会生成:

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

configure(javaProjects()){
...
}

项目(':functional-tests'){
....
}

即使我将功能测试版本移动到它自己的单独的build.gradle文件,结果也是一样的。有人可以指出如何实现这一目标吗?

解决方案

我发现了一个更好的解决方案,命令行或通过构建文件。



例如,要运行除功能测试以外的所有测试,请运行: pre> $ gradle check -x:功能测试:检查

然后在构建项目时,可以让子项目生成但排除他们的测试。

  $ gradle clean assemble -x :功能测试:检查

更好的选择是禁用构建文件中的功能测试,除非财产设置。例如,在您的 build.gradle 中您可以添加:

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

通过这种方式,除非您指定特定的构建属性,否则功能测试总是会被跳过:

  $ gradle check 
$ gradle -PunctionTests检查

希望有帮助!



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?

解决方案

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!

这篇关于Gradle从完整构建中排除特定的子项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆