Kotlin plugin asks to be added to the root project as well but doing so makes the build crash!

The Kotlin Gradle plugin was loaded multiple times in different subprojects, which is not supported and may break the build. 
This might happen in subprojects that apply the Kotlin plugins with the Gradle 'plugins { ... }' DSL if they specify explicit versions, even if the versions are equal.
Please add the Kotlin plugin to the common parent project or the root project, then remove the versions in the subprojects.
If the parent project does not need the plugin, add 'apply false' to the plugin line.
See: https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl

Problem is, if i do so (even with apply false), the Android plugin will complain!

FAILURE: Build failed with an exception.

* What went wrong:
> com.android.build.gradle.BaseExtension

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Unable to load class 'com.android.build.gradle.BaseExtension'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)

The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)

Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

Here’s the hierarchy of the project:

|-projectA (Kotlin JVM library)
|-projectB (Kotlin JVM library)
|-projectC (Android app)

Now, projectB has api(project(":projectA")) and projectC has api(project(":projectA")) so that:


Using Gradle version 5.4/5.4.1, I had no issues so far (with no Kotlin plugin line in the rootProject ). How you’d solve this?

Hi. Can you please submit a bug report at http://kotl.in/issue with a sample project to reproduce this problem? Thanks!

Done! https://youtrack.jetbrains.com/issue/KT-31643?project=kt :slight_smile: Thanks!

1 Like

See the comment on the issue describing the root cause and the workaround: https://youtrack.jetbrains.com/issue/KT-31643#focus=streamItem-27-3510019.0-0

The problem resurfaced with Kotlin 1.4.x. Atm I am declaring plugins in settings.gradle.kts using the new pluginManagement.plugins lambda. The root project is kind of empty (just for authoring with no plugins applied), one sub-project is a K/MPP with JS and JVM targets, while the other sub-project is a K/JVM one. If I try to declare all my plugins in the root project with apply false the build/sync crashed with:

A problem occurred configuring project ':data'.
> Failed to notify project evaluation listener.
   > org.jetbrains.kotlinx.serialization.gradle.SerializationGradleSubplugin$Companion.isEnabled(Lorg/gradle/api/Project;)Z
   > org.jetbrains.kotlinx.serialization.gradle.SerializationGradleSubplugin$Companion.isEnabled(Lorg/gradle/api/Project;)Z
   > org.jetbrains.kotlinx.serialization.gradle.SerializationGradleSubplugin$Companion.isEnabled(Lorg/gradle/api/Project;)Z

If not declaring the plugins at all in the root project the build/sync goes fine as expected. Now two questions arises:

  • the obvious first is why does the build crashes if you declare all of your plugins with apply false in the root project
  • why in the first place the Kotlin plugin warns you about versioning if everything has been already centralized by pluginManagement.plugins in settings.gradle.kts

Plugins as declared in settings.gradle.kts:

pluginManagement {

    plugins {

        val kotlinVersion: String by settings
        val nodePluginVersion: String by settings
        val sshPluginVersion: String by settings

        kotlin("multiplatform") version kotlinVersion
        kotlin("jvm") version kotlinVersion
        kotlin("plugin.serialization") version kotlinVersion
        id("org.jetbrains.dokka") version kotlinVersion
        id("com.github.node-gradle.node") version nodePluginVersion
        id("org.hidetake.ssh") version sshPluginVersion




1 Like

I narrowed down the problem to the buildscript { } block in the script files that were erroring. The buildscript was adding few Kotlin-unrelated dependencies but the act of manipulating the classpath made the warnings appear.

The solution I found was to build the classpath for all build scripts using buildSrc/build.gradle.kts. By adding all dependencies there, Kotlin and non-Kotlin, the error disappeared.

Also I’d like to point out that centralizing the classpath construction solved both the nasty NoClassDefFoundError and Failed to notify project evaluation listener kotlinx.serialization plugin errors.

1 Like

Kotlin plugin is applied to the project :business_module:module_rank but we cannot find the KaptTask. Make sure you apply the kotlin-kapt plugin because it is necessary to use kotlin with data binding.

it’s my error message, i don’t konw how deal it