Creating another type of test task in Java

Hi all,

In our project we have both ‘tests’ and ‘speedtests’. The latter are performance tests and take a long time, so we don’t want them running every time we test compiler correctness.

Right now, here’s the sourceSets configuration:

sourceSets { {
    srcDir 'src'
    srcDir 'protobuf/java'
    srcDir 'third-party-src'
  } {
    srcDir 'test'
  } {
    srcDir 'speedtest'
  task speedtest(type: Test) {
  testClassesDir = sourceSets.speedtest.output.classesDir
  classpath = sourceSets.speedtest.runtimeClasspath
  include = 'speedtest/**'

If I run ‘gradle build’ it will compile everything successfully and run the tests in the ‘test’ subdirectory. It does not run ‘speedtestClasses’ to compile the ‘speedtest’ code. When I run ‘speedtestClasses’ manually, it fails—presumably because it does not know that, like test, it needs to copy all the settings from ‘compile’ and ‘runtime’ and ‘testCompile’ and ‘testRuntime’.

Is there a way to easily get it to clone ‘test’'s settings and act in a similar way?


For an example on how to set up an additional ‘Test’ task, see ‘samples/java/withIntegrationTests’ in the full Gradle distribution.

Thanks so much! Is there no way to find this information online? Most users won’t start by cloning the gradle git…

You can either download the full distribution, or browse the GitHub repo.