Exclude src/main in test task


(Michael Migdol) #1

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?


(Peter Niederwieser) #2

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


(Michael Migdol) #3

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…


(Peter Niederwieser) #4

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:

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.


(Michael Migdol) #5

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