Slackbot
07/29/2022, 5:28 AMEli Graber
07/29/2022, 5:56 AMcompileOnly in my library, but now when I use the library in one of my projects I get the error:
Unable to load class 'org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper'.
This is an unexpected error. Please file a bug containing the idea.log file.Eli Graber
07/29/2022, 6:25 AMsettings.gradle.kts
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath("my-library")
}
}
If I take that out, then everything works.
However, I want to use a function from my library in the dependencyResolutionManagement block to add a repository (I have repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) set).
I can add the buildscript block above to build.gradle.kts and then everything works fine (except I can't use the library to add the repository).Eli Graber
07/29/2022, 6:34 AMkotlin-dslMartin
07/29/2022, 9:33 AMcompileOnly is the good call. More generally, your lib also shouldn't have kotlin-stdlib in its dependencies so you should have kotlin.stdlib.default.dependency=false (but that is most likely not really related to your immediate problem)Martin
07/29/2022, 9:34 AMUnable to load class 'org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper'.
Do you have the stacktrace for this? Every code you write that needs the KGP symbols needs to be called from something like
plugins.withId("org.jetbrains.kotlin.jvm") { // or ".multiplatform"
// do stuff here
}Martin
07/29/2022, 9:35 AMMartin
07/29/2022, 9:37 AMEli Graber
07/29/2022, 5:49 PMcompileOnly for the kotlin plugin, but if I add the kotlin plugin as a classpath dependency in the project the error still occurs.
* Exception is:
java.lang.NoClassDefFoundError: org/jetbrains/kotlin/gradle/dsl/ExplicitApiMode
at com.eygraber.gradle.kotlin.KgpKt.configureKgp$default(kgp.kt:17)
at Build_gradle.<init>(build.gradle.kts:27)
at Program.execute(Unknown Source)
at org.gradle.kotlin.dsl.execution.Interpreter$ProgramHost.eval(Interpreter.kt:532)
at org.gradle.kotlin.dsl.execution.Interpreter$ProgramHost.evaluateSecondStageOf(Interpreter.kt:438)
at Program.execute(Unknown Source)
at org.gradle.kotlin.dsl.execution.Interpreter$ProgramHost.eval(Interpreter.kt:532)
at org.gradle.kotlin.dsl.execution.Interpreter.eval(Interpreter.kt:184)Martin
07/29/2022, 5:51 PMplugins.withId("org.jetbrains.kotlin....") {}Martin
07/29/2022, 5:52 PMMartin
07/29/2022, 5:54 PMEli Graber
07/29/2022, 5:56 PMplugins.withType(KotlinBasePluginWrapper::class.java) before interacting with it, and in the project I tried wrapped the usage of the library in that and it still didn't work.
I have 2 plugins that are compileOnly in the library; detekt and Kotlin. If I make Kotlin implementation then the error changes to not being able to load detekt classesMartin
07/29/2022, 5:58 PMplugins.withType(KotlinBasePluginWrapper::class.java)Can that even work? That'd mean
KotlinBasePluginWrapper is already in the classpath...Martin
07/29/2022, 5:59 PMMartin
07/29/2022, 6:00 PMsettings.gradle.kts and build.gradle.kts in your project and load everything from regular (non-buildscript) buildSrc dependenciesMartin
07/29/2022, 6:01 PMEli Graber
07/29/2022, 6:21 PMsettings.gradle.kts buildscript, and because the library has a compileOnly dependency on kotlinGradleDsl, there is no implementation being used.
If I add classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21") to the settings.gradle.kts buildscript then it works, but if I only add it to the build.gradle.kts buildscript it doesn't work, even though the NoClassDefFoundError is happening in the build.gradle.kts.Martin
07/29/2022, 6:23 PMEli Graber
07/29/2022, 6:24 PMkotlin-dsl, and a project that has a classpath dependency on that library in settings.gradle.kts and applies kotlin-dsl in build.gradle.kts
Unless I include a classpath dependency on kgp in the project's settings.gradle.kts, I get NoClassDefFoundError for code that's called from the library in build.gradle.ktsMartin
07/29/2022, 6:26 PMsettings.gradle.kts part? Usually KGP and others are applied in build.gradle.ktsEli Graber
07/29/2022, 6:27 PMdependencyResolutionManagement because I have repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) set (which only allows repos to be configured in that block in settings.gradle.kts)Martin
07/29/2022, 6:29 PMMartin
07/29/2022, 6:33 PMMartin
07/29/2022, 6:34 PMMartin
07/29/2022, 6:35 PMMartin
07/29/2022, 6:35 PMEli Graber
07/29/2022, 6:40 PMbuild.gradle.kts buildscript as well, and everything works fine as long as I don't load it in the settings.gradle.kts buildscriptMartin
07/29/2022, 6:40 PMMartin
07/29/2022, 6:42 PMbuild.gradle.kts should take precedenceMartin
07/29/2022, 6:42 PMMartin
07/29/2022, 6:42 PMMartin
07/29/2022, 6:42 PMhttps://storage.googleapis.com/programming-idioms-pictures/idiom/149/princess-java.pngā¾
Eli Graber
07/29/2022, 6:43 PMEli Graber
07/29/2022, 7:09 PMcompileOnly for kgp and detekt because of this error:
Error resolving plugin [id: 'io.gitlab.arturbosch.detekt', version: '1.21.0']
> The request for this plugin could not be satisfied because the plugin is already on the classpath with an unknown version, so compatibility cannot be checked.
By adding the kgp dependency as implementation instead of compileOnly the issue is resolved.
However I now get a NoClassDefFoundError for detekt plugin classes.
So the issue is that if detekt is implementation I get the error about resolving the plugin, and if it is compileOnly I get the NoClassDefFoundError. Adding the detekt plugin to the settings.gradle.kts buildscript dependencies results in the error about resolving the plugin.
And now I realize the problem is that because the library brings kgp and detekt onto the project's classpath, I can't specify the version when applying the kgp and detekt plugins.
However, I'm applying them using version catalogs (alias(libs.plugins.kotlin), etc...) which I thought should allow the same version to be specified (https://github.com/gradle/gradle/pull/19015) however I just realized that Gradle doesn't know the version of the plugin on the classpath, which is not supported.
So the solution is to use implementation for the plugins in the library, and not specify the plugin version in the project šMartin
07/29/2022, 7:12 PM