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