Gradle, Kotlin and generated code

I have been using generated code in my tests with Java and everything was working fine. However when using that code under Gradle I can compile it but not run it.

From my build.gradle:

sourceSets { test_generated { kotlin.srcDir 'generated-src/antlr/test/' } } compileTestKotlin.source sourceSets.test_generated.kotlin, sourceSets.test.kotlin

It compiles but when I run it I get java.lang.NoClassDefFoundError

The same tests run well inside intelliJ. My suspicion is that somehow the Gradle plugin for Kotlin does not include all the compiled dirs in the runtime classpath for tests

Also compile the test code both using Java and Kotlin seems to fix the issue:

sourceSets {
test_generated {
java.srcDir ‘generated-src/antlr/test/’
}
}
compileTestJava.source sourceSets.test_generated.java
compileTestKotlin.source sourceSets.test.kotlin, sourceSets.test_generated.java