Cannot exclude the test task in Gradle

We are using a gradle script to build our project. We need to exclude the test task. We use the bellow command to exclude the test task.

gradle build -x test

But it does not exclude the test task.

Gradle script

group = ‘com.test’

apply plugin: ‘java’

buildDir = “$projectDir/bin”

configurations { providedCompile }

repositories {

flatDir { dirs “$LIB” } }

sourceSets {

main {

java {

srcDir “$projectDir/src”


test {

java.srcDirs = ["$projectDir/test"]

resources.srcDirs = ["$projectDir/test"]

compileClasspath += configurations.testCompile

runtimeClasspath += sourceSets.test.output


} }

dependencies {

testCompile (group: ‘junit’, name:‘junit’, version:‘4.11’)

testCompile (group: ‘org.hamcrest’ , name: ‘hamcrest-core’ , version: ‘1.3’) }

test {

include “**/*Test.class”

testLogging {

// Show that tests are run in the command-line output

events ‘started’, ‘passed’

} }

‘-x test’ will exclude the ‘test’ task. How do you tell it doesn’t?

I am very sorry Peter. It does not exclude the test task. we added the bellow line in the build script.


Then we could exclude the test task using -x test. Please explain me why It doesn’t exclude the test task before adding the above line?

So what happens when you do ‘gradle build -x test’? How do you tell that the ‘test’ task isn’t excluded? And what’s the output of ‘gradle -v’?

When we do “gradle build -x test” the test task executed. After added the line “check.dependsOn.remove(test)” in gradle script when we do “gradle build -x test” the test was excluded. We added the testLogging events ‘started’ and ‘passed’ to show whether the test was executed or not.

The output of gradle -v is “Gradle 1.11”.

Works fine for me. Are you typing ‘gradle build -x test’ into a console?

Yes. I typed “gradle build -x test”. I am also wonder why It doesn’t exclude the test task without adding the line “check.dependsOn.remove(test)”.

If you add that line, you won’t even have to use ‘-x test’ anymore. Without a reproducible example, there’s not much I can do. I’d be surprised if this was a general Gradle problem. One thing you can try is whether you get the same behavior with other Gradle versions/installations, and whether you get it on other machines.

One thing I noticed is that you have

test {
     include "*/Test.class"

I would be surprised if this pattern matched your test classes. (I suspect you actually want ‘**/*Test.class’). So it looks to me like this test task wouldn’t run any tests anyway - could it actually be a different task be running the tests?