How to set useFallbackCompilerSearch?

Quick question for JetBrains or build folks. The way kotlin-gradle-plugin resolves the compiler plugin seems to have changed recently (1.2.60 I believe), and the old way is now behind a flag, useFallbackCompilerSearch, which is here.

How do I actually set this value to true?

To answer my own question:

  1. Add kotlin.useFallbackCompilerSearch=true to your gradle.properties file, or
  2. Append -Pkotlin.useFallbackCompilerSearch=true to your Gradle build command.

Based on this and this.

@nanodeath Yes, you’ve described the correct way to use the flag. However the flag is intended only as a workaround just in case there is some case that cannot be fixed by other means.
We’ve changed the way Kotlin plugin searches the compiler:

  • Previously it tried to find the compiler in Kotlin Gradle plugin dependencies. There is no way to do this reliably in Gradle, so the solution was fragile and slow.
  • Since 1.2.60 Kotlin Gradle plugin resolves ‘kotlinCompilerClasspath’ configuration in each subproject it is applied to. By default kotlinCompilerClasspath resolves ‘org.jetbrains.kotlin:kotlin-compiler-embeddable:<PLUGIN_VERSION>’ artifact in each subproject with kotlin plugin. If project uses mavenCentral or jcenter repositories, then everything should work. If something breaks, then a subproject does not use these repositories, but that also means that it cannot resolve ‘org.jetbrains.kotlin:kotlin-stdlib’ from these repositories either. So if you use mavenCentral or jcenter, then you should just add them to problematic subprojects.

The dependency should resolve through mavenCentral, but only trough project repository, not buildscript one.

Won’t work:

buildscript {
     repositories {
         mavenCentral()
     }
     dependencies {
          classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.60'
     }
}

apply plugin: 'kotlin'

Should work:

buildscript {
     repositories {
         mavenCentral()
     }
     dependencies {
          classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.60'
     }
}

apply plugin: 'kotlin'

repositories {
    // this repo should be available in every subproject that uses kotlin
    mavenCentral() // or jcentrer
}

What exactly is kotlinCompilerClasspath ? Can I override it? Is it a Gradle property?

It’s a dependency configuration. Basically it’s a named collection of dependencies in Gradle that can be resolved to file collection. Files from the resolved configuration are used as a classpath for the compiler process.
Currently Kotlin plugin does something like this:

// ...
val compilerClasspath = project.configurations.create("kotlinCompilerClasspath").defaultDependencies {
    project.dependencies.create("org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinPluginVersion)
}
// ...
runProcess(compilerClasspath.resolve(), compilerArgs)

You can use Gradle dependency management to add dependencies to kotlinCompilerClasspath configuration:

// build.gradle
apply plugin: 'kotlin'

dependencies {
      kotlinCompilerClasspath files(PATHS_TO_KOTLIN_COMPILER_CLASSPATH)
}

kotlinCompilerClasspath is expected to resolve to kotlin-compiler-embeddable artifact with its dependencies (this may change in future: Kotlin plugin might start using other artifact).