Because of dependencies propagation from the `buil...
# kotlin-dsl
c
Because of dependencies propagation from the
buildSrc
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:
Copy code
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?
Ah. It looks like gradle will tell me which version it does expect if I specify a version, so it's useless to specify it... So I don't know how to fix the
already on the classpath with an unknown version
error. Here's my `buildSrc/settings.build.kts`:
Copy code
rootProject.name = "buildSrc"

dependencyResolutionManagement {
  @Suppress("UnstableApiUsage")
  repositories {
    mavenCentral()
    gradlePluginPortal()
  }

  versionCatalogs {
    create("libs") {
      from(files("../gradle/libs.versions.toml"))
    }
  }
}
my
buildSrc/build.gradle.kts
:
Copy code
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`:
Copy code
# Do not automatically add the kotlin-stdlib dependency
kotlin.stdlib.default.dependency = false
Any help is welcome...
m
Copy code
// 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 build
Do this in your main build
Copy code
plugins {
  id("org.jetbrains.kotlin.multiplatform") // no version sepcified here
}
Copy code
# 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 anyways
c
My main build has:
Copy code
plugins {
  alias(libs.plugins.multiplatform) apply false
  ...
}
which refers to my gradle/libs.versions.toml:
Copy code
[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?
Replacing the versioned
alias
with your proposal in the root
build.gradle.kts
still produces the same error.
The project is public, should you have the time to investigate:
git clone <http://gitlab.republicate.com/claude/skorm.git>
v
How 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.
c
I removed it everywhere and the error is still here:
Copy code
~/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)
m
Copy code
alias(libs.plugins.multiplatform) apply false
FWIW, this contains a version
Can't tell if it's commented out or if it's just the output of
rg
but replace all the
alias(libs.plugins.multiplatform)
witih
id("org.jetbrains.kotlin.multiplatform")
(If it's commented out, your build probably won't go very far since your build scripts probably need it anyways)
v
That's not the point though. Read his error more closely ;-)
👍 1
c
It was commented. I replaced it everywhere with
id(...)
(just with
apply false
in the root) - the error is still here.
v
It does not complain about KMP which is commented in line 11 and 12. It complains about K/JVM in line 10. Both plugins are in the same code artifact, so adding one to the classpath also adds the other.
☝️ 1
m
Good catch 👍
c
Line 10 is just the beginning of the plugin block:
Copy code
10 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 }
m
That's poor error reporting from Gradle but it's still the cause of the error
v
Well, then line 12 in what you just posted 🙄
m
I guess Gradle could track the exact line, might be worth filing a bug
👍 1
But that's a completely different issue 🤷
👆 1
c
I made some progress. I've been told that "The Kotlin JVM and Multiplatform plugins are both in the same JAR", so I did the same (replace
alias()
by
id()
in subprojects using the jvm) and the error disappeared. Of course I encountered another error, but nothing to do with this one.
👍 1
👌 1
v
I'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. :-)
c
Ah, "both plugins"... right. Thanks, anyway.
v
Actually all of the KGP plugin