diff --git a/TestProjectGroovy/build.gradle b/TestProjectGroovy/build.gradle index 97919ce..328f6f1 100644 --- a/TestProjectGroovy/build.gradle +++ b/TestProjectGroovy/build.gradle @@ -30,9 +30,9 @@ dependencies { mindustry { dependency { - mindustry version: 'v146' + mindustry version: latest // mindustryMirror version: latest - arc version: 'v146' + arc version: latest } modMeta { name = 'mgpp-groovy' diff --git a/TestProjectKt/build.gradle.kts b/TestProjectKt/build.gradle.kts index 1a39fa1..c3ef96c 100644 --- a/TestProjectKt/build.gradle.kts +++ b/TestProjectKt/build.gradle.kts @@ -46,8 +46,8 @@ tasks.register("iconMaker") { } mindustry { dependency { - mindustry on "v146" - arc on "v146" + mindustry on latest + arc on latestRelease } modMeta { name = "mgpp-kt" diff --git a/main/src/R.kt b/main/src/R.kt index 9fd040b..84c8839 100644 --- a/main/src/R.kt +++ b/main/src/R.kt @@ -142,6 +142,10 @@ object R { * [The GitHub API to fetch the latest commit of mirror](https://github.com/Anuken/MindustryJitpack/commits/main) */ const val mirrorLatestCommit = "https://api.github.com/repos/Anuken/MindustryJitpack/commits/main" + /** + * [The GitHub API to fetch the latest release of mirror](https://github.com/Anuken/MindustryJitpack/releases/latest) + */ + const val mirrorLatestRelase = "https://api.github.com/repos/Anuken/MindustryJitpack/releases/latest" /** * [The GitHub API to fetch the latest commit of arc](https://github.com/Anuken/Arc/commits/master) */ diff --git a/main/src/mindustry/model/Dependency.kt b/main/src/mindustry/model/Dependency.kt index 1747810..ef18234 100644 --- a/main/src/mindustry/model/Dependency.kt +++ b/main/src/mindustry/model/Dependency.kt @@ -154,6 +154,7 @@ class DependencySpec( val version = map["version"]?.toString() ?: throw GradleException("No version specified for `mindustryMirror`") when (version) { Notation.latest.toString() -> mindustryMirrorLatestCommit() + Notation.latestRelease.toString() -> mindustryMirrorLatestCommit() else -> mindustryMirror(version) } } @@ -194,6 +195,24 @@ class DependencySpec( } mindustryMirror(latestVersion) } + /** + * Fetch the latest Mindustry from [mindustry jitpack](https://github.com/Anuken/Mindustry). + * + * **Potential Issue** It has a very small chance that it won't work when the new version was just released. + */ + fun mindustryMirrorLatestRelease() { + val latestVersion = target.fetchLatestVersion("mindustry-mirror-release-dependency") { + try { + val url = URL(R.github.tag.mirrorLatestCommit) + val json = Jval.read(url.readText()) + return@fetchLatestVersion json.getString("tag_name") + } catch (e: Exception) { + target.logger.warn("Failed to fetch the exact latest version of mindustry jitpack, so use ${R.version.defaultOfficial} instead") + return@fetchLatestVersion R.version.defaultOfficial + } + } + mindustryMirror(latestVersion) + } /** * Fetch the latest Arc from [arc jitpack](https://github.com/Anuken/Arc). * @@ -325,6 +344,7 @@ class DependencySpec( infix fun mirror(notation: Notation) { when (notation) { Notation.latest -> mindustryMirrorLatestCommit() + Notation.latestRelease -> mindustryMirrorLatestRelease() else -> throw GradleException("Unknown dependency notation of mindustry mirror $notation") } }