Is there an easy way in Gradle to have some kind o...
# eap
c
Is there an easy way in Gradle to have some kind of flag that changes the Kotlin version? I have a few open source libraries and I'd be willing to have a CI that runs once a week using the latest Kotlin EAP to try to early-detect things going wrong. However, I don't know to set it up on the Gradle side (I'm good on the CI side) Ideally I'd like some kind of
./gradlew -Peap
which runs the build using the latest Kotlin EAP version instead of the stable one
1
All my projects already depend on a custom Gradle convention plugin, so I could put whichever logic is required there.
b
Would'nt evaluating this property (as you suggested it) in settings.gradle make it available to all build.gradle files? then you could reference it
c
But the convention plugins are in another repository, so their
settings.gradle.kts
isn't invoked when a downstream project uses them 🤔
b
I meant in the project, irrespective of conventions. Isn't the kotlin version picked up from a version catalog and you're done anyway?
w
I don't think there's a built-it mechanism specifically for Kotlin versions or something like that, but you can have your own rule that everywhere you apply Kotlin version you first check some property like
my_custom_property_gradle_version
. If it exists — you override the version with its value, if it doesn't, you use the current value. Last I tried, having a true single source of truth for Kotlin version was slightly annoying because of buildscript classpath being different than project ones, and needing to match Kotlin version with other dependencies like KSP or serialization
c
> Isn't the kotlin version picked up from a version catalog and you're done anyway? No. The project depends on the convention plugin, which itself depends on Kotlin. The projects don't contain the Kotlin version specified anywhere.
b
You could change the dependency in the conventions to a compile-only dependency and specify the kotlin plug in in the version catalog. Then you can pipe the version into the catalog in your Ci pipeline
o
I do have the following setup in my libraries: https://github.com/whyoleg/cryptography-kotlin/blob/main/build-settings/src/main/kotlin/cksettings.kotlin-version-override.settings.gradle.kts (copied from one to another, to lazy to extract into a separate project) • kotlin version is defined in version catalog • there is
kotlin-version-override.settings.gradle.kts
which should be applied in
settings.gradle.kts
of every project which uses version catalog • CI is run like this: https://github.com/whyoleg/cryptography-kotlin/blob/186a42095596d697d1bddc7cc7085464ebe24591/.github/workflows/ci-kotlin-eap.yml#L38 it's possible to run CI on schedule, or directly (as on screenshot) with specific version
👌 1
m
We have a script that modifies the version and commits it to a separate long lived branch: https://github.com/apollographql/apollo-kotlin/blob/main/.github/workflows/bump-kotlin-nightlies.yml
👌 1
One of the advantages is that if you need to keep separate modifications for some reason, they can also live there
j
I have my convention plugin published but I am able to change the Kotlin version in two ways, one for the KGP and another to override the version catalog Kotlin version to ensure all dependencies use the correct version. For example, I need it in compiler plugins to replace the Kotlin version declared and used by Hubdle with whatever version I want to test including dev versions. https://github.com/JavierSegoviaCordoba/kopy/blob/main/settings.gradle.kts
Copy code
buildscript {
    dependencies {
        val kotlinVersion: String =
            file("$rootDir/gradle/libs.versions.toml")
                .readLines()
                .first { it.contains("jetbrains-kotlin") }
                .split("\"")[1]
Copy code
val kotlinModule =
            file("$rootDir/gradle/libs.versions.toml")
                .readLines()
                .first { it.contains("jetbrains-kotlin-gradle-plugin") }
                .split("\"")[1]
Copy code
val kotlinDependency = "$kotlinModule:$kotlinVersion"
        classpath(kotlinDependency)
    }
}
Copy code
hubdleSettings {
    catalog { //
        version(hubdleCatalogVersion)
        replaceVersion(
            "javiersc-kotlin-compiler-extensions" to kotlinCompilerExtensionsVersion,
            "jetbrains-kotlin" to kotlinVersion,
        )
    }
}
That hubdle settings is just using the official way to replace version catalog versions under the hood.