Test task scan directory

My plugin creates additional classes dir (kotlin-classes/[sourceSetName]) to a SourceSet output. It is needed to do correct cross compilation with java Jar task successfully handles this (adds compiled classes to jar archives).

But Test task seems to ignore this directory when scanning for test classes. Is there any way for single Test task to scan several classes directories? (e.g., java and kotlin)

The ‘Test’ task type currently only handles scanning one directory. You’ll have to aggregate the classes yourself…

task aggregateTestClasses(type: Copy) {
  from compileTestJava
  from compileTestKotlin
  into "$buildDir/classes/test-java-and-kotlin"
}
  test {
  dependsOn aggregateTestClasses
  testClassesDir aggregateTestClasses.destinationDir
}

I see. Thank you.

The ‘Test’ task type assumes a single test classes directory (‘testClassesDir’). By default, Gradle’s Java, Groovy, and Scala plugins all compile into the same output directory (also when joint-compiling). The separation is per source set, not per language.