Edoardo Luppi
12/15/2023, 9:26 PMCLOVIS
12/15/2023, 9:39 PMtarget.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
// …whatever you want…
}
The code block will be executed when the Kotlin Multiplatform plugin is applied. If it is never applied, the code is never executed.CLOVIS
12/15/2023, 9:41 PMpluginManager.hasPlugin
, but I don't recommend it because it creates an ordering relationship (it will only return true
if the Kotlin plugin is applied before yours, whereas with withPlugin
the order makes no difference)Edoardo Luppi
12/15/2023, 10:20 PMEdoardo Luppi
12/15/2023, 10:20 PMCLOVIS
12/15/2023, 10:29 PMCLOVIS
12/15/2023, 10:31 PMcompileOnly
dependency on KGP, this way the downstream project can still use whichever Kotlin version they want.
However, if in the future a new KGP version has binary incompatibilities with the one you're compiling against, the user won't be warned, and the build will crash with a ClassNotFoundError (or similar)Edoardo Luppi
12/15/2023, 10:35 PMcompileOnly
and the user hasn't declared the Kotlin plugin? Won't that mean my plugin will throw as soon as it gets loaded for missing classes?CLOVIS
12/15/2023, 10:42 PMpluginManager.withPlugin
, the KGP has already been applied for sure, so using KGP symbols is safe (assuming binary compatibility).CLOVIS
12/15/2023, 10:43 PMCLOVIS
12/15/2023, 10:45 PMEdoardo Luppi
12/15/2023, 10:46 PMCLOVIS
12/15/2023, 10:47 PMimplementation
dependency using rich versions with a lower bound but no preferred version? I haven't tested it. [EDIT. No you couldn't, since your goal is for KGP to be an optional dependency]CLOVIS
12/15/2023, 10:47 PMcompileOnly
+`pluginManager.withPlugin` is what the ecosystem uses.
I'm not a fan of compileOnly
either 😕Edoardo Luppi
12/15/2023, 10:48 PMimplementation
too just to not have to deal with missing classes, but then I'm forcing a KGP version on users, or at least I'm messing with the user's class path