Is there a way to only apply Kotlin for unit tests

We have been told not to use Kotlin for the production code of our app, but there is no reason why we couldn’t use it in unit tests, so am wondering if there is an easy way to configure the gradle plugin for Android such that Kotlin is only supported in unit tests and will not compile for the main code?

Isn’t it enough to use testCompile for declaring Kotlin dependency if you are using Gradle?

Nope, it can still compile kotlin files in the main source directories.

You can configure source sets for kotlin using src.main.kotlin (or test). By default they are equal to src.main.java + “src/main/kotlin”

Using your information here is a working solution:

afterEvaluate {
   android.sourceSets.all { sourceSet ->
      if (!sourceSet.name.startsWith("test"))
      {
         sourceSet.kotlin.setSrcDirs([])
      }
   }
}