a19bd2ed2e
It's going to be deprecated in Gradle 8.3 There's currently no way to pass a `org.gradle.api.provider.Provider` to the JavaExec.systemProperty or Test.systemProperty. There's a workaround using `org.gradle.process.CommandLineArgumentProvider`, but I intentionally don't rework these calls as Gradle is going to allow passing providers to configure system properties: https://github.com/gradle/gradle/issues/12247#issuecomment-1568427242 ^KTI-1473 In Progress
63 lines
2.3 KiB
Kotlin
63 lines
2.3 KiB
Kotlin
@file:Suppress("HasPlatformType")
|
|
|
|
import java.io.File
|
|
|
|
val buildVersionFilePath = layout.buildDirectory.file("build.txt")
|
|
val buildVersion by configurations.creating
|
|
val buildNumber: String by rootProject.extra
|
|
val kotlinVersion: String by rootProject.extra
|
|
|
|
val writeBuildNumber by tasks.registering {
|
|
val versionFile = buildVersionFilePath
|
|
val buildNumber = buildNumber
|
|
inputs.property("version", buildNumber)
|
|
outputs.file(versionFile)
|
|
doLast {
|
|
with(versionFile.get().asFile) {
|
|
parentFile.mkdirs()
|
|
writeText(buildNumber)
|
|
}
|
|
}
|
|
}
|
|
|
|
artifacts.add(buildVersion.name, buildVersionFilePath) {
|
|
builtBy(writeBuildNumber)
|
|
}
|
|
|
|
|
|
|
|
val writeStdlibVersion by tasks.registering {
|
|
val kotlinVersionLocal = kotlinVersion
|
|
val versionFile = rootDir.resolve("libraries/stdlib/src/kotlin/util/KotlinVersion.kt")
|
|
inputs.property("version", kotlinVersionLocal)
|
|
outputs.file(versionFile)
|
|
|
|
fun Task.replaceVersion(versionFile: File, versionPattern: String, replacement: (MatchResult) -> String) {
|
|
check(versionFile.isFile) { "Version file $versionFile is not found" }
|
|
val text = versionFile.readText()
|
|
val pattern = Regex(versionPattern)
|
|
val match = pattern.find(text) ?: error("Version pattern is missing in file $versionFile")
|
|
val group = match.groups[1]!!
|
|
val newValue = replacement(match)
|
|
if (newValue != group.value) {
|
|
logger.lifecycle("Writing new standard library version components: $newValue (was: ${group.value})")
|
|
versionFile.writeText(text.replaceRange(group.range, newValue))
|
|
} else {
|
|
logger.info("Standard library version components: ${group.value}")
|
|
}
|
|
}
|
|
|
|
doLast {
|
|
replaceVersion(versionFile, """fun get\(\): KotlinVersion = KotlinVersion\((\d+, \d+, \d+)\)""") {
|
|
val (major, minor, _, optPatch) = Regex("""^(\d+)\.(\d+)(\.(\d+))?""").find(kotlinVersionLocal)?.destructured ?: error("Cannot parse current version $kotlinVersionLocal")
|
|
"$major, $minor, ${optPatch.takeIf { it.isNotEmpty() } ?: "0" }"
|
|
}
|
|
}
|
|
}
|
|
|
|
val writePluginVersion by tasks.registering // Remove this task after removing usages in the TeamCity build
|
|
|
|
val writeVersions by tasks.registering {
|
|
dependsOn(writeBuildNumber, writeStdlibVersion)
|
|
}
|