Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 673
Paddy Avatar asked Feb 02 '15 06:02

Paddy


People also ask

How do you avoid transitive dependencies in Gradle?

When you specify a dependency in your build script, you can provide an exclude rule at the same time telling Gradle not to pull in the specified transitive dependency. For example, say we have a Gradle project that depends on Google's Guava library, or more specifically com.

How do I exclude tasks in Gradle?

To skip any task from the Gradle build, we can use the -x or –exclude-task option. In this case, we'll use “-x test” to skip tests from the build. As a result, the test sources aren't compiled, and therefore, aren't executed.


1 Answers

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!

like image 136
Scott Avatar answered Sep 24 '22 02:09

Scott