From 7bb4d65507ae05997ce51aea98f3eff55601167c Mon Sep 17 00:00:00 2001 From: Cdm2883 Date: Mon, 30 Sep 2024 18:29:55 +0800 Subject: [PATCH] feat: control versions at the same place --- build.gradle.kts | 19 +++++++++++++++++++ example/src/main/resources/plugin.json | 3 ++- gradle/libs.versions.toml | 2 ++ plugin/src/main/resources/plugin.json | 2 +- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6ac5fbc..7a158d0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,3 +4,22 @@ plugins { alias(libs.plugins.kotlin.jvm) apply false alias(libs.plugins.gradleup.shadow) apply false } + +subprojects { + afterEvaluate { + + if (projectDir.resolve("src/main/resources/plugin.json").exists()) { + val version = rootProject.libs.versions.allaymc.kotlinx.get() + + tasks.named("processResources") { + doLast { + val origin = file("src/main/resources/plugin.json") + val processed = file("${layout.buildDirectory.get()}/resources/main/plugin.json") + val content = origin.readText().replace("\${version}", version) + processed.writeText(content) + } + } + } + + } +} diff --git a/example/src/main/resources/plugin.json b/example/src/main/resources/plugin.json index 1d8d0b0..50d3ac8 100644 --- a/example/src/main/resources/plugin.json +++ b/example/src/main/resources/plugin.json @@ -1,10 +1,11 @@ { "entrance": "vip.cdms.allaymc.kotlinx.KotlinxExamplePlugin", "name": "KotlinxExamplePlugin", - "version": "0.1.0-alpha", + "version": "${version}", "dependencies": [ { "name": "KotlinxPlugin", + "version": "${version}", "optional": false } ] diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c925602..3496bb6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,4 +1,6 @@ [versions] +allaymc-kotlinx = "0.1.0-alpha" + kotlin = "2.0.20" gradleup-shadow = "8.3.0" diff --git a/plugin/src/main/resources/plugin.json b/plugin/src/main/resources/plugin.json index 83b8717..75d678c 100644 --- a/plugin/src/main/resources/plugin.json +++ b/plugin/src/main/resources/plugin.json @@ -5,7 +5,7 @@ "authors": [ "MineBuilder" ], - "version": "0.1.0-alpha", + "version": "${version}", "dependencies": [], "website": "https://github.com/MineBuilders/allaymc-kotlinx" } \ No newline at end of file