"Unresolved reference: implementation" by using subprojects in kotlin-gradle

Not sure how you're not also getting an error by nesting the plugins { } block under subprojects { } As stated in Limitations of the plugins DSL:

The plugins {} block must also be a top level statement in the buildscript. It cannot be nested inside another construct (e.g. an if-statement or for-loop).

So to fix your issues, move the plugins {} to the top and imperatively apply the plugins in the subprojects {} block:

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

plugins {
    kotlin("jvm") version "1.3.50" apply false
}

subprojects {
    apply {
        plugin("org.jetbrains.kotlin.jvm")
    }

    group = "project"
    version = "0.0.1-SNAPSHOT"

    repositories {
        mavenCentral()
    }

    val implementation by configurations

    dependencies {
        implementation(kotlin("stdlib-jdk8"))
    }

    tasks.withType<KotlinCompile> {
        kotlinOptions.jvmTarget = "1.8"
    }
}

You can read more about the apply false part in the Method details of PluginDependenciesSpec which is the type/scope of the plugins {} block.

You can read more about the val implementation by configurations part in the Understanding what to do when type-safe model accessors are not available


Is important to define the repositories in settings.gradle.kts (project) so that the dependencies of the subprojects are recognized.

settings.gradle.kts (project)

pluginManagement {
    repositories {
        maven("https://dl.bintray.com/kotlin/kotlin-eap")
        mavenCentral()
        maven("https://plugins.gradle.org/m2/")
    }
}
rootProject.name = "project"

include("app")

build.gradle.kts (project)

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

        plugins {
            java
            kotlin("jvm") version "1.4-M3" apply false
        }

subprojects {
    apply {
        plugin("org.jetbrains.kotlin.jvm")
    }

    repositories {
        maven("https://dl.bintray.com/kotlin/kotlin-eap")
        mavenCentral()
    }

    val implementation by configurations

    dependencies {
        implementation(kotlin("stdlib-jdk8"))
    }

    tasks.withType<KotlinCompile> {
        kotlinOptions.jvmTarget = "1.8"
    }
}

To define plugins for each submodule separately use the lambda apply { plugin("pluginId") }

build.gradle.kts (:app)

apply {
    plugin("org.jetbrains.kotlin.jvm")
}

dependencies {
    implementation(kotlin("stdlib-jdk8"))
}

GL

Tags:

Gradle

Kotlin