mikehearn
06/30/2022, 12:52 PMkenkyee
06/30/2022, 12:58 PMimplementation(platform("org.jetbrains.kotlin:kotlin-bom"))
Usually, that has a version...I think it's an oversight that this line doesn't have a version#mikehearn
06/30/2022, 12:58 PMkenkyee
06/30/2022, 12:59 PMmikehearn
06/30/2022, 12:59 PMkenkyee
06/30/2022, 1:00 PMjendrik
06/30/2022, 1:00 PMkotlin-bom
parts and kotlin-stdlib
parts from buildSrc/src/main/kotlin/demo.kotlin-common-conventions.gradle.kts
This is done by the Kotlin plugin automatically these days.buildSrc/build.gradle.kts
dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:YOUR-VERSION")
}
mikehearn
06/30/2022, 1:01 PMEmil Kantis
06/30/2022, 1:03 PMbuildSrc/build.gradle.kts
buildSrc/build.gradle.kts
dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0") // Version here was missing in gradle docs
}
kenkyee
06/30/2022, 1:05 PMmikehearn
06/30/2022, 1:06 PMw: Consider providing an explicit dependency on kotlin-reflect 1.7 to prevent strange errors
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
e: /Users/mike/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.7.0/51736992f422993a1e741051bdf3c12801bc1ca1/kotlin-stdlib-common-1.7.0.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
e: /Users/mike/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.7.0/a5f42c684ad9003160ef0d0f693ecf0ba7b13549/kotlin-stdlib-1.7.0.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
kenkyee
06/30/2022, 1:06 PMEmil Kantis
06/30/2022, 1:07 PM7.5-rc-3
it would likely work.. you could also probably fix it by removing something from what is done in buildSrc, I'll have a look at what the buildSrc stuff is doing.. 🙂mikehearn
06/30/2022, 1:07 PMEmil Kantis
06/30/2022, 1:10 PMmikehearn
06/30/2022, 1:10 PMkenkyee
06/30/2022, 1:10 PMFleshgrinder
06/30/2022, 1:10 PMbuild.gradle.kts
of the project containing your script plugin. Inside your script plugin you do not refer to any version.
buildSrc/build.gradle.kts
plugins {
`kotlin-dsl`
}
dependencies {
api("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0")
}
repositories {
mavenCentral()
gradlePluginPortal()
}
buildSrc/src/main/kotlin/my-convention.gradle.kts
plugins {
kotlin("jvm") // version is inherited from runtime classpath of project
}
dependencies {
// No need for Kotlin BOM, automatically applied by `kotlin("jvm")`
// No need for Kotlin STD, automatically applied by `kotlin("jvm")`
// Other dependencies go here.
}
repositories {
mavenCentral()
}
some-project/build.gradle.kts
plugins {
id("my-convention")
}
The warning you posted above is not enough to tell what the problem could be.mikehearn
06/30/2022, 1:12 PMkenkyee
06/30/2022, 1:13 PMFleshgrinder
06/30/2022, 1:14 PMmikehearn
06/30/2022, 1:14 PMFleshgrinder
06/30/2022, 1:19 PMplugins {
`kotlin-dsl`
}
… inside buildSrc/build.gradle.kts
that leads to the warning. buildSrc
is a special weirdo sub-project and there is nothing you can do about this other than not using buildSrc
.
This is the reason why the Gradle folks want to phase it out. 😉jendrik
06/30/2022, 1:20 PM1.7.0
as suggested here, it builds without any error or warning.
Imo the setup is correct (from the Gradle perspective). I don’t think that this has anything to do with Gradle’s built-in Kotlin version in this case. It shouldn’t.mikehearn
06/30/2022, 1:20 PMkenkyee
06/30/2022, 1:21 PMmikehearn
06/30/2022, 1:21 PMVampire
06/30/2022, 1:22 PMThis is the reason why the Gradle folks want to phase it outNot really. The warning is serious and can lead to problems. It is not caused by Gradle, it is caused by bad plugins. A plugin has to cope with the Kotlin runtime that is provided and hard fixed by Gradle. To be compatible with a specific Gradle version, the plugin has to also be compatible with the embedded Kotlin version. If the plugin depends on a newer Kotlin version, that is bad. If it depends on some lib that depends on a newer Kotlin version, that is bad. Build logic should not directly or transitively bring in any Kotlin stdlib dependencies as they will conflict with the embedded version.
mikehearn
06/30/2022, 1:22 PMFleshgrinder
06/30/2022, 1:22 PMbuildSrc
and get rid of the warning:
settings.gradle.kts
includeBuild("gradle/plugins/my-convention")
// Soon to be:
// pluginManagement {
// includeBuild("gradle/plugins/my-convention")
// }
gradle/plugins/my-convention/build.gradle.kts
plugins {
`kotlin-dsl`
}
dependencies {
api("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0")
}
repositories {
mavenCentral()
gradlePluginPortal()
}
The rest is just like above.
@jendrik I would have thought so too.mikehearn
06/30/2022, 1:23 PMEmil Kantis
06/30/2022, 1:24 PMmikehearn
06/30/2022, 1:24 PMjendrik
06/30/2022, 1:24 PMThe binary version of its metadata is 1.7.1, expected version is 1.5.1.
I would suspect that somewhere in the build, or in a plugin you use, the version to compile to is explicitly set to 1.5.x
Vampire
06/30/2022, 1:25 PMYes, because it's so weird. To ditchEven if you do so, the reason for the warning probably persists, but is just not determined. If you only have the mixture at runtime rather than compiletime, it just "silently" fails with even more cryptic errors eventually.and get rid of the warning:buildSrc
Fleshgrinder
06/30/2022, 1:25 PM1.5.1
is also not a Kotlin version Gradle ever used. This clearly shows that it has nothing to do with Gradle.mikehearn
06/30/2022, 1:25 PMVampire
06/30/2022, 1:27 PMI'm not so sure about that. 1.5.1 is not a Kotlin version at all. It also doesn't state so. It says "binary version of its metadata". This is probably the metadata version used in 1.5.10 or 1.5.20 or whatever.is also not a Kotlin version Gradle ever used. This clearly shows that it has nothing to do with Gradle.1.5.1
Fleshgrinder
06/30/2022, 1:28 PMmikehearn
06/30/2022, 1:28 PMFleshgrinder
06/30/2022, 1:31 PMimplementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
This line collides with kotlin-dsl
.mikehearn
06/30/2022, 1:35 PMFleshgrinder
06/30/2022, 1:36 PMmikehearn
06/30/2022, 1:38 PMFleshgrinder
06/30/2022, 1:39 PMincludeBuild
. Which comes with it's own UX issues.mikehearn
06/30/2022, 1:40 PMbuildSrc
which has to use Kotlin 1.5 or 1.6 and that's a normal "project", not a "composite build"?Fleshgrinder
06/30/2022, 1:42 PMbuildSrc
is special. @jendrik’s and @Vampire’s comments – who both know Gradle very well – suggest that it should work for buildSrc
. Which, purely conceptually, makes sense, since it's a build executed in isolation before any other build. However, I haven't used buildSrc
in a long while and cannot say for sure without creating a build with a buildSrc
and running it.mikehearn
06/30/2022, 1:42 PMVampire
06/30/2022, 1:42 PMbuildSrc
too.
And if you build any build-logic to be used by Gradle, you have to stick to the Kotlin runtime embedded in the target Gradle version, whether you build it in buildSrc
or in an included build doesn't matter.Fleshgrinder
06/30/2022, 1:43 PMVampire
06/30/2022, 1:44 PMFleshgrinder
06/30/2022, 1:44 PMVampire
06/30/2022, 1:45 PMmikehearn
06/30/2022, 1:48 PMephemient
06/30/2022, 2:18 PMjendrik
07/01/2022, 9:02 AMmikehearn
07/01/2022, 11:35 AMmbonnin
07/14/2022, 7:07 PMtasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java) {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + "-Xskip-metadata-version-check"
}
}