This message was deleted.
# plugin-development
s
This message was deleted.
j
changing
implementation
to
compileOnly
maybe fix your problem
but to be honest I never add the
jvm
one as
implementation
, I add the generic one
org.jetbrains.kotlin:kotlin-gradle-plugin
c
compileOnly
only sort of works, ran into the expected challenges. As this distribution contains multiple plugins (only a few of which are Kotlin related), applying a base plugin on the root project of a multi-project build fails with NoClassDefFoundError for Kotlin classes, even though the root project isn’t applying any Kotlin plugins. Adding the Kotlin plugin to the root project resolves this, but isnt’ desirable (the root project isn’t a Kotlin project and should not have/need that plugin).
t
So your initial error is probably due to that too: root project has the transitive embeddedKotlinVersion in its classpath, and subproject tries to add another version. As a workaround (for both approaches), you can probably add the Kotlin plugin to the root project with
apply(false)
to only add it to the buildscript classpath without applying the plugin. I'd look at why the root project throws a NoClassDefFoundError though: if it's supposed to work on projects which aren't Kotlin projects, then it should be able to detect whether the project is a Kotlin project and only access those classes in those cases.
c
thanks. it does work with
apply(false)
. It isn’t the root project that fails with that error, it’s subprojects when the root project is missing the Kotlin plugin (even though subprojects have it applied, before my plugin).
t
Ah, the dreaded plugin classloader hierarchy… subproject plugin classloader inherits parent project classloader, so your plugin is from the parent classloader and cannot see Kotlin plugin's classes in child classloader. https://dev.to/autonomousapps/abusing-gradle-s-class-loader-hierarchy-for-fun-and-profit-oca
c
Indeed! ☠️
e
KGP wants to be loaded in the root project anyway though