kotlin-compiler-embeddable missing within gradle build

Viewed 822

I am trying to setup a multiproject gradle/kotlin build and I am getting following error:

Could not determine the dependencies of task ':compileKotlin'.
> Could not resolve all files for configuration ':kotlinCompilerClasspath'.
   > Cannot resolve external dependency org.jetbrains.kotlin:kotlin-compiler-embeddable:1.4.10 because no repositories are defined.
     Required by:
         project :

Strange thing is the empty project :.

My simplifiged build.gradle.kts looks like this:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    base
    kotlin("jvm") version "1.4.10"
}

buildscript {
    extra["kotlin_version"] = "1.4.10"

    repositories {
        jcenter()
        mavenCentral()
    }
}

subprojects {
    apply(plugin = "kotlin")

    repositories {
        jcenter()
        mavenCentral()
    }

    tasks.compileKotlin {
        kotlinOptions.jvmTarget = "11"
    }

    tasks.compileTestKotlin {
        kotlinOptions.jvmTarget = "11"
    }

    dependencies {
        implementation("org.jetbrains.kotlin:kotlin-stdlib:${rootProject.extra["kotlin_version"]}")
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${rootProject.extra["kotlin_version"]}")
    }
}

Do I need to duplicate the repositories within the buildscript section?

What is that is causing the error above?

1 Answers

It seems like your repositories { ... } configuration done in the subproject section is sufficient, but it is only applied to the supbrojects but not the root project itself (which has the Kotlin plugin applied, too, and whose task :compileKotlin is failing).

There are two ways to fix this.

First, you could move the repositories { ... } section from subprojects { ... } to a new block allprojects { ... } (thus applied to the root project as well).

Or, if you don't actually need the Kotlin plugin in the root project (i.e. you don't have Kotlin code there), you can add .apply(false) to your plugin declaration:

plugins {
    kotlin("jvm").version("1.4.10").apply(false)
}
Related