From fe46ea474099c7c933057e83a581e348731df784 Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 18 Nov 2021 03:11:27 +0000 Subject: [PATCH] Automatically generate VersionConstants.kt --- tools/gradle-plugin/.gitignore | 1 + tools/gradle-plugin/build.gradle.kts | 20 ++++++------------- ...stants.kt => VersionConstants.kt.template} | 4 ++-- 3 files changed, 9 insertions(+), 16 deletions(-) create mode 100644 tools/gradle-plugin/.gitignore rename tools/gradle-plugin/src/main/kotlin/{VersionConstants.kt => VersionConstants.kt.template} (68%) diff --git a/tools/gradle-plugin/.gitignore b/tools/gradle-plugin/.gitignore new file mode 100644 index 000000000..cf58f6de0 --- /dev/null +++ b/tools/gradle-plugin/.gitignore @@ -0,0 +1 @@ +src/main/kotlin/VersionConstants.kt \ No newline at end of file diff --git a/tools/gradle-plugin/build.gradle.kts b/tools/gradle-plugin/build.gradle.kts index 34151e53a..4adf7e196 100644 --- a/tools/gradle-plugin/build.gradle.kts +++ b/tools/gradle-plugin/build.gradle.kts @@ -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) + ) } } diff --git a/tools/gradle-plugin/src/main/kotlin/VersionConstants.kt b/tools/gradle-plugin/src/main/kotlin/VersionConstants.kt.template similarity index 68% rename from tools/gradle-plugin/src/main/kotlin/VersionConstants.kt rename to tools/gradle-plugin/src/main/kotlin/VersionConstants.kt.template index b4914cec7..c191a2318 100644 --- a/tools/gradle-plugin/src/main/kotlin/VersionConstants.kt +++ b/tools/gradle-plugin/src/main/kotlin/VersionConstants.kt.template @@ -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 } \ No newline at end of file