Thomas Broyer
07/07/2024, 11:30 AMkotlin-dsl produces Kotlin 1.4-compatible bytecode, compatible all the way down to Gradle 6.8.
IIUC (I'm not well versed into Kotlin compatibility), using Gradle 8.0–8.2 would only possibly allow for Kotlin 1.5 (3 versions down from 1.8), i.e. Gradle 7.2; and bumping to >=8.3 cuts that to Gradle 7.5 (Kotlin 1.6)
Do I understand properly? and what would you recommend?
(I'm thinking about rewriting from Kotlin to Java, but still need Kotlin for extension functions, but could then possibly just use kotlin("jvm") rather than `embedded-kotlin`/`kotlin-dsl`; also, I don't think shipping variants is worse the hassle, this is for a small plugin, not AGP or KGP)Martin
07/07/2024, 1:46 PMkotlin("jvm").version("2.0.0") with apiVersion /`languageVersion`Martin
07/07/2024, 1:47 PMMartin
07/07/2024, 2:04 PMGradle 8.0–8.2 would only possibly allow for Kotlin 1.5I like to think of it the other way around: the version of Kotlin you use determines the Gradle compatibility. You can use Gradle 8.8 and compile with Kotlin 1.5 (or any other version) using
kotlin("jvm")Martin
07/07/2024, 2:12 PM# gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
# build.gradle.kts
plugins {
id(kotlin("jvm")).version("2.0.0")
}
dependencies {
compileOnly("dev.gradleplugins:gradle-api:6.8)
}
kotlin {
compilerOptions {
// this is deprecated but looks like it's still working
apiVersion.set(KotlinVersion.KOTLIN_1_4)
languageVersion.set(KotlinVersion.KOTLIN_1_4)
}
}
And then run integration tests with both Gradle 6.8 and Gradle 8.8Martin
07/07/2024, 2:18 PMbuild.gradle.kts users get better APIs? I’ve been trying to avoid any Kotlin constructs in plugin public API (extensions, function types, etc...) because it’s so easy to forget about Groovy caller doing soThomas Broyer
07/07/2024, 2:49 PMBTW, I’m curious about that part: “need Kotlin for extension functions”. Does that meanNo, that without them Groovy DSL users get a better experience, because Kotlin DSL doesn't generate type-safe accessors for everythingusers get better APIs?build.gradle.kts
John
07/12/2024, 4:48 PMtasks.withType<KotlinCompile> {
kotlinOptions {
languageVersion = "1.4"
apiVersion = "1.4"
}
}John
07/12/2024, 4:48 PMkotlin-dsl plugin as well, and it worksThomas Broyer
07/12/2024, 5:32 PMThomas Broyer
07/12/2024, 5:34 PMkotlin-dsl (or possibly just embedded-kotlin) and reconfiguring the languageVersion and apiVersion to "1.4" to keep compatibility down to Gradle 6.8 !Thomas Broyer
07/12/2024, 5:40 PMMartin
07/12/2024, 5:55 PMkotlin-dsl though and use the plain org.jetbrains.kotlin.jvm cause it gives more control (and also forced me to understand the sam-with-receiver magic) (and is not bound to the Gradle version)Martin
07/12/2024, 5:56 PMMartin
07/12/2024, 6:00 PMThomas Broyer
07/12/2024, 7:16 PMgradle init for a new project and noticed that generating a plugin project using Kotlin as implementation language uses the Kotlin JVM plugin (and not `kotlin-dsl`; which I suppose is more tailored for "private to the build" convention plugins)John
07/12/2024, 7:51 PMMartin
07/12/2024, 10:51 PMkotlin-dsl should die, replaced by declarative Gradle. kotlin-dsl tries too much to look declarative while under the hood everything is imperative.