# Exclude src/main in test task

**URL:** <https://discuss.gradle.org/t/exclude-src-main-in-test-task/5933>\
**Category:** Old Forum Archive\
**Created:** [October 6, 2011, 7:39am UTC](https://discuss.gradle.org/t/exclude-src-main-in-test-task/5933 "2011-10-06T07:39:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelMigdol](https://avatars.discourse-cdn.com/v4/letter/m/d78d45/32.png) [@MichaelMigdol](https://discuss.gradle.org/u/MichaelMigdol)\
**Post date:** [October 6, 2011, 7:39am UTC](https://discuss.gradle.org/t/exclude-src-main-in-test-task/5933/1 "2011-10-06T07:39:00Z")

</div>

I’m trying to override the behavior of the test task for a groovy project so that the code in src/main does not get compiled. I tried the following:

sourceSets {

test {

groovy {

srcDir ‘test/groovy’

}

} }

However, the code in src/main is still getting compiled when I run “gradle test”. Can someone point me in the right direction?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [October 13, 2011, 12:04am UTC](https://discuss.gradle.org/t/exclude-src-main-in-test-task/5933/2 "2011-10-13T00:04:00Z")

</div>

What’s the broader issue that you are trying to solve? Why don’t you want the test task to trigger a compile?

---

<div class="post-metadata">

**Author:** ![MichaelMigdol](https://avatars.discourse-cdn.com/v4/letter/m/d78d45/32.png) [@MichaelMigdol](https://discuss.gradle.org/u/MichaelMigdol)\
**Post date:** [October 13, 2011, 12:33am UTC](https://discuss.gradle.org/t/exclude-src-main-in-test-task/5933/3 "2011-10-13T00:33:00Z")

</div>

I have some functional tests (black box) that have no direct dependencies on the source code of the app. I could put them in their own project but would prefer to keep them together…

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [October 13, 2011, 1:07am UTC](https://discuss.gradle.org/t/exclude-src-main-in-test-task/5933/4 "2011-10-13T01:07:00Z")

</div>

If you override the ‘test’ source set’s compileClasspath and runtimeClasspath to no longer include sourceSets.main.output, the task dependency will go away. For example:

```gradle
sourceSets {
  test {
    compileClasspath = configurations.testCompile
    runtimeClasspath = output + configurations.testRuntime
  }
}

```

Alternatively, you could introduce a new source set (say ‘functionalTest’) along with a new test task. The java/withIntegrationTests sample in the full distribution shows how this is achieved.

---

<div class="post-metadata">

**Author:** ![MichaelMigdol](https://avatars.discourse-cdn.com/v4/letter/m/d78d45/32.png) [@MichaelMigdol](https://discuss.gradle.org/u/MichaelMigdol)\
**Post date:** [October 13, 2011, 2:49am UTC](https://discuss.gradle.org/t/exclude-src-main-in-test-task/5933/5 "2011-10-13T02:49:00Z")

</div>

The java withIntegrationTests example was just what I was looking for. Thanks for the pointer!
