Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support variable Kotlin and project versions #201

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import util.kotlinVersionParsed
import util.libs

plugins {
Expand Down Expand Up @@ -46,22 +45,22 @@ apiValidation {
nonPublicMarkers.add(Const.INTERNAL_RPC_API_ANNOTATION)
}

val kotlinVersion: KotlinVersion by extra
val kotlinVersionFull: String by extra

allprojects {
group = "org.jetbrains.kotlinx"
version = rootProject.libs.versions.kotlinx.rpc.get()
}

println("kotlinx.rpc project version: $version, Kotlin version: $kotlinVersion")
println("kotlinx.rpc project version: $version, Kotlin version: $kotlinVersionFull")

// If the prefix of the kPRC version is not Kotlin gradle plugin version – you have a problem :)
// Probably some dependency brings kotlin with the later version.
// To mitigate so, refer to `versions-root/kotlin-version-lookup.json`
// and its usage in `gradle-conventions-settings/src/main/kotlin/settings-conventions.settings.gradle.kts`
val kotlinGPVersion = getKotlinPluginVersion().kotlinVersionParsed()
if (kotlinVersion != kotlinGPVersion) {
error("KGP version mismatch. Project version: $kotlinVersion, KGP version: $kotlinGPVersion")
val kotlinGPVersion = getKotlinPluginVersion()
if (kotlinVersionFull != kotlinGPVersion) {
error("KGP version mismatch. Project version: $kotlinVersionFull, KGP version: $kotlinGPVersion")
}

// necessary for CI js tests
Expand Down
4 changes: 2 additions & 2 deletions compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ plugins {
alias(libs.plugins.conventions.gradle.doctor)
}

val kotlinVersion: KotlinVersion by extra
val kotlinVersionFull: String by extra
val rpcVersion: String = libs.versions.kotlinx.rpc.get()

allprojects {
group = "org.jetbrains.kotlinx"
version = "$kotlinVersion-$rpcVersion"
version = "$kotlinVersionFull-$rpcVersion"
}
1 change: 0 additions & 1 deletion gradle-conventions-settings/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ configurations.configureEach {
}
}

val kotlinVersion: KotlinVersion by extra
val isLatestKotlinVersion: Boolean by extra

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pluginManagement {
fun Path.bufferedReader(
charset: Charset = Charsets.UTF_8,
bufferSize: Int = DEFAULT_BUFFER_SIZE,
vararg options: OpenOption
vararg options: OpenOption,
): BufferedReader {
return BufferedReader(
InputStreamReader(
Expand All @@ -32,6 +32,7 @@ fun Path.bufferedReader(

object SettingsConventions {
const val KOTLIN_VERSION_ENV_VAR_NAME = "KOTLIN_VERSION"
const val LIBRARY_VERSION_ENV_VAR_NAME = "LIBRARY_VERSION"
const val EAP_VERSION_ENV_VAR_NAME = "EAP_VERSION"

const val KSP_VERSION_ALIAS = "ksp"
Expand Down Expand Up @@ -82,10 +83,18 @@ fun loadLookupTable(rootDir: Path, kotlinVersion: String): Pair<Map<String, Stri
.split("\n")
.takeIf { it.size >= 2 }
?.run {
latest = get(1).substringBefore(',')
when (val versionsRow = singleOrNull { it.startsWith(kotlinVersion) }) {
null -> null
else -> first().asCsvValues() to versionsRow.asCsvValues()
first().asCsvValues() to when (val versionsRow = singleOrNull { it.startsWith(kotlinVersion) }) {
// resolve latest for an unknown version
// considers that unknown versions are too new and not yet added
null -> {
latest = kotlinVersion
get(1).asCsvValues()
}

else -> {
latest = get(1).substringBefore(',')
versionsRow.asCsvValues()
}
}
}
?.takeIf { (keys, values) -> keys.size == values.size }
Expand Down Expand Up @@ -156,16 +165,22 @@ fun VersionCatalogBuilder.resolveKotlinVersion(versionCatalog: Map<String, Strin
?: error("Expected to resolve '${SettingsConventions.KOTLIN_VERSION_ALIAS}' version")
}

// Resolves core kotlinx.rpc version (without Kotlin version prefix) from Versions Catalog.
// Updates it with EAP_VERSION suffix of present.
// Resolves a core kotlinx.rpc version (without a Kotlin version prefix) from the Version Catalog.
// Uses LIBRARY_VERSION_ENV_VAR_NAME instead if present
fun VersionCatalogBuilder.resolveLibraryVersion(versionCatalog: Map<String, String>) {
val eapVersion: String = System.getenv(SettingsConventions.EAP_VERSION_ENV_VAR_NAME)
?.let { "-eap-$it" } ?: ""
val libraryCatalogVersion = versionCatalog[SettingsConventions.LIBRARY_CORE_VERSION_ALIAS]
val libraryCoreVersion: String = System.getenv(SettingsConventions.LIBRARY_VERSION_ENV_VAR_NAME)
?: versionCatalog[SettingsConventions.LIBRARY_CORE_VERSION_ALIAS]
?: error("Expected to resolve '${SettingsConventions.LIBRARY_CORE_VERSION_ALIAS}' version")
val libraryCoreVersion = libraryCatalogVersion + eapVersion

version(SettingsConventions.LIBRARY_CORE_VERSION_ALIAS, libraryCoreVersion)
val eapVersion: String = System.getenv(SettingsConventions.EAP_VERSION_ENV_VAR_NAME)
?.let {
when (it){
"SNAPSHOT" -> "-$it"
else -> "-eap-$it"
}
} ?: ""

version(SettingsConventions.LIBRARY_CORE_VERSION_ALIAS, libraryCoreVersion + eapVersion)
}

fun String.kotlinVersionParsed(): KotlinVersion {
Expand Down Expand Up @@ -193,11 +208,13 @@ dependencyResolutionManagement {
val isLatestKotlin = latestKotlin == kotlinVersion

extra["kotlinVersion"] = kotlinVersion.kotlinVersionParsed()
extra["kotlinVersionFull"] = kotlinVersion
extra["isLatestKotlinVersion"] = isLatestKotlin

gradle.rootProject {
allprojects {
this.extra["kotlinVersion"] = kotlinVersion.kotlinVersionParsed()
this.extra["kotlinVersionFull"] = kotlinVersion
this.extra["isLatestKotlinVersion"] = isLatestKotlin
}
}
Expand Down
4 changes: 2 additions & 2 deletions ksp-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode

val kotlinVersion: KotlinVersion by extra
val kotlinVersionFull: String by extra
val rpcVersion: String = libs.versions.kotlinx.rpc.get()

allprojects {
group = "org.jetbrains.kotlinx"
version = "$kotlinVersion-$rpcVersion"
version = "$kotlinVersionFull-$rpcVersion"
}

plugins {
Expand Down