Claude Brisson
04/26/2025, 9:01 AMbuildSrc directory, it looks like I have to define an explicit version for the kotlin-dsl plugin in it.
If I don't, I get the following error:
Error resolving plugin [id: 'org.jetbrains.kotlin.multiplatform', version: '2.1.0', apply: false]
> 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.
But this plugin seems to have its own versioning scheme, and it's not clear to me which version to specify for a given gradle version (8.8 as it stands) and a given kotlin version (2.1.0).
Is this documented somewhere?Claude Brisson
04/26/2025, 9:19 AMalready on the classpath with an unknown version error.
Here's my `buildSrc/settings.build.kts`:
rootProject.name = "buildSrc"
dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
repositories {
mavenCentral()
gradlePluginPortal()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
my buildSrc/build.gradle.kts :
plugins {
`kotlin-dsl`
}
dependencies {
implementation(libs.kotlin.plugin)
}
gradlePlugin {
plugins {
register("skormGradlePlugin") {
id = "skorm.gradle.plugin"
implementationClass = "com.republicate.skorm.SkormGradlePlugin"
}
}
}
and my `buildSrc/gradle.properties`:
# Do not automatically add the kotlin-stdlib dependency
kotlin.stdlib.default.dependency = false
Any help is welcome...Martin
04/26/2025, 9:49 AM// buildSrc/build.gradle.kts
dependencies {
implementation(libs.kotlin.plugin)
}
This ☝️ is what decides the version of KGP used in your main build. As long as you have that, you should not specify versions when applying KGP in your main buildMartin
04/26/2025, 9:50 AMplugins {
id("org.jetbrains.kotlin.multiplatform") // no version sepcified here
}Martin
04/26/2025, 9:51 AM# buildSrc/gradle.properties
# Do not automatically add the kotlin-stdlib dependency
kotlin.stdlib.default.dependency = false
This ☝️ doesn't change much. Gradle is going to put its own version of the stdlib at runtime anywaysClaude Brisson
04/26/2025, 9:54 AMplugins {
alias(libs.plugins.multiplatform) apply false
...
}
which refers to my gradle/libs.versions.toml:
[versions]
kotlin = "2.1.0"
...
[plugins]
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
How do I get a specific version of kotlin if I can't specify it here?!
Also, why would gradle say that the plugin is on the classpath with an unspecified version?Claude Brisson
04/26/2025, 9:57 AMalias with your proposal in the root build.gradle.kts still produces the same error.Claude Brisson
04/26/2025, 9:58 AMgit clone <http://gitlab.republicate.com/claude/skorm.git>Vampire
04/26/2025, 10:26 AMHow do I get a specific version of kotlin if I can't specify it here?!
As Martin said, you already specify the version in
buildSrc/build.gradle.kts as dependency, so why declaring it again?
Also, why would gradle say that the plugin is on the classpath with an unspecified version?
It didn't say "unspecified", but "unknown". This is, because
buildSrc is always a specialty. It is a separate build, the result of which including dependencies is put to a class loader that is the parent of the root build script classpath class loader. For plugins added to the classpath using the plugins { ... } block, Gradle tracks and knows the versions and can know whether it is compatible. But with plugins added via other means, like as buildSrc dependency, it does not know the version and this this error pops up.
You can for example put your build logic into an included build instead of buildSrc (which I prefer anyway), then the dependencies are added the normal way to the classpath and the versions are tracked accordingly.
Replacing the versioned alias with your proposal in the root build.gradle.kts still produces the same error.
The whole line in the root buildscript is pointless, remove it instead. As you have
apply false you would only add it to the classpath, but as you already have it on the classpath through depending on it from buildSrc, it already is on the classpath and the line useless but only visual clutter.
That you still get the error means, that you probably still have a version where you actually apply the plugin in one of your subprojects.Claude Brisson
04/26/2025, 10:31 AM~/g/skorm (main|✚5) $ ./gradlew clean
Calculating task graph as no cached configuration is available for tasks: clean
Type-safe project accessors is an incubating feature.
FAILURE: Build failed with an exception.
* Where:
Build file '/home/claude/git/skorm/build.gradle.kts' line: 10
* What went wrong:
Error resolving plugin [id: 'org.jetbrains.kotlin.jvm', version: '2.1.0', apply: false]
> 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.
* 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>.
BUILD FAILED in 612ms
4 actionable tasks: 1 executed, 3 up-to-date
Configuration cache entry stored.
~/g/skorm (main|✚5) [1] $ rg multiplatform **/*.kts
build.gradle.kts
11: // id("org.jetbrains.kotlin.multiplatform")
12: // alias(libs.plugins.multiplatform) apply false
skorm-api-client/build.gradle.kts
11: // alias(libs.plugins.multiplatform)
examples/bookshelf/build.gradle.kts
2: // alias(libs.plugins.multiplatform)
skorm-common/build.gradle.kts
11: // alias(libs.plugins.multiplatform)
skorm-core/build.gradle.kts
11: // alias(libs.plugins.multiplatform)Martin
04/26/2025, 10:33 AMalias(libs.plugins.multiplatform) apply false
FWIW, this contains a versionMartin
04/26/2025, 10:34 AMrg but replace all the alias(libs.plugins.multiplatform) witih id("org.jetbrains.kotlin.multiplatform")Martin
04/26/2025, 10:35 AMVampire
04/26/2025, 10:36 AMClaude Brisson
04/26/2025, 10:37 AMid(...) (just with apply false in the root) - the error is still here.Vampire
04/26/2025, 10:38 AMMartin
04/26/2025, 10:38 AMClaude Brisson
04/26/2025, 10:41 AM10 plugins {
11 id("org.jetbrains.kotlin.multiplatform") apply false
12 alias(libs.plugins.jvm) apply false
13 alias(libs.plugins.dokka)
14 signing
15 `maven-publish`
16 alias(libs.plugins.nexusPublish)
17 }Martin
04/26/2025, 10:42 AMVampire
04/26/2025, 10:42 AMMartin
04/26/2025, 10:43 AMMartin
04/26/2025, 10:43 AMClaude Brisson
04/26/2025, 10:50 AMalias() by id() in subprojects using the jvm) and the error disappeared. Of course I encountered another error, but nothing to do with this one.Vampire
04/26/2025, 3:18 PMI've been told that "The Kotlin JVM and Multiplatform plugins are both in the same JAR"Yes, I told you that in my next to last comment above. :-)
Claude Brisson
04/26/2025, 3:20 PMVampire
04/26/2025, 3:20 PM