Question: My `settings.gradle` file looks like:

```
include "serverTest", "shared"

```

And the serverTest `build.gradle` file looks like:

```
group = 'gradle'
version = '1.0'
defaultTasks 'build'
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = JavaVersion.VERSION_1_6

dependencies
{
  compile project(':shared')
}

```

The directory structure is: The top level holds the settings.gradle file and it has folders shared and serverTest in it. Then in the serverTest directory there is the build.gradle file.

When I run gradle at the top level it outputs:

```
:shared:compileJava UP-TO-DATE
:shared:processResources UP-TO-DATE
:shared:classes UP-TO-DATE
:shared:jar UP-TO-DATE
:serverTest:compileJava UP-TO-DATE
:serverTest:processResources UP-TO-DATE
:serverTest:classes UP-TO-DATE
:serverTest:jar UP-TO-DATE
:serverTest:assemble UP-TO-DATE
:serverTest:compileTestJava
:serverTest:processTestResources UP-TO-DATE
:serverTest:testClasses
:serverTest:test

```

I don't want it to execute the task `:serverTest:test` though. I tried changing my defaultTasks to just compileJava but that didn't work, does anyone else have any ideas?

Answer: 
Well this question has been asked in different ways , the main theme of the question is;

**How to exclude sub tasks of build task?**

1 . **gradle build -x test**

The above instruction is helpful while executing gradle build command from CLI; this exludes test task, but we want to exclude test task programmatically in build.gradle file. Look below the answer for the respective question.

2 . **check.dependsOn -= test**

Copy this small script in your build.gradle file. 
Now when you execute **gradle build** from CLI, your tests won't run at all.

Cheers !
You could try to disable the task only if a build task is present... Something like:

```
project(":serverTest").test.onlyIf { !gradle.taskGraph.hasTask(":shared:build") }

```