Automatically generate VersionConstants.kt

This commit is contained in:
Him188 2021-11-18 03:11:27 +00:00
parent 9711c5eb3e
commit fe46ea4740
3 changed files with 9 additions and 16 deletions

1
tools/gradle-plugin/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
src/main/kotlin/VersionConstants.kt

View File

@ -111,20 +111,12 @@ tasks {
val fillBuildConstants by registering {
group = "mirai"
doLast {
projectDir.resolve("src").walk().filter { it.name == "VersionConstants.kt" }.single()
.let { file ->
file.writeText(
file.readText()
.replace(
Regex("""const val CONSOLE_VERSION = ".*"""")
) {
"""const val CONSOLE_VERSION = "${Versions.console}""""
}
.replace(
Regex("""const val CORE_VERSION = ".*"""")
) { """const val CORE_VERSION = "${Versions.core}"""" }
)
}
projectDir.resolve("src/main/kotlin/VersionConstants.kt").apply { createNewFile() }
.writeText(
projectDir.resolve("src/main/kotlin/VersionConstants.kt.template").readText()
.replace("$\$CONSOLE_VERSION$$", Versions.console)
.replace("$\$CORE_VERSION$$", Versions.core)
)
}
}

View File

@ -10,6 +10,6 @@
package net.mamoe.mirai.console.gradle
internal object VersionConstants {
const val CONSOLE_VERSION = "2.8.0" // value is written here automatically during build
const val CORE_VERSION = "2.8.0" // value is written here automatically during build
const val CONSOLE_VERSION = "$$CONSOLE_VERSION$$" // value is written here automatically during build
const val CORE_VERSION = "$$CORE_VERSION$$" // value is written here automatically during build
}