1+ import nl.littlerobots.vcu.plugin.versionSelector
12import org.jetbrains.kotlin.gradle.dsl.JvmTarget
23
34ext {
@@ -22,14 +23,27 @@ plugins {
2223 alias(libs.plugins.kotlinx.atomicfu) apply false
2324 alias(libs.plugins.rikka.refine) apply false
2425 alias(libs.plugins.loc) apply false
25- alias(libs.plugins.benmanes.version)
2626 alias(libs.plugins.littlerobots.version)
2727}
2828
29- val normalVersionRegex by lazy { " ^[0-9\\ .]+" .toRegex() }
29+ // ./gradlew versionCatalogUpdate --interactive
30+ versionCatalogUpdate {
31+ versionSelector {
32+ val a = it.currentVersion
33+ val b = it.candidate.version
34+ isSameTypeVersion(a, b) && isNewerVersion(a, b)
35+ }
36+ }
37+ projectDir.resolve(" ./gradle/libs.versions.updates.toml" ).apply {
38+ if (exists()) {
39+ delete()
40+ }
41+ }
42+
43+ val versionReg = " ^[0-9\\ .]+" .toRegex()
3044fun isSameTypeVersion (currentVersion : String , newVersion : String ): Boolean {
31- if (normalVersionRegex .matches(currentVersion)) {
32- return normalVersionRegex .matches(newVersion)
45+ if (versionReg .matches(currentVersion)) {
46+ return versionReg .matches(newVersion)
3347 }
3448 arrayOf(" alpha" , " beta" , " dev" , " rc" ).forEach { v ->
3549 if (currentVersion.contains(v, true )) {
@@ -38,14 +52,20 @@ fun isSameTypeVersion(currentVersion: String, newVersion: String): Boolean {
3852 }
3953 throw IllegalArgumentException (" Unknown version type: $currentVersion -> $newVersion " )
4054}
41- tasks.withType< com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask > {
42- rejectVersionIf {
43- ! isSameTypeVersion(currentVersion, candidate.version)
44- }
45- }
46- // ./gradlew versionCatalogUpdate --interactive
47- projectDir.resolve(" ./gradle/libs.versions.updates.toml" ).apply {
48- if (exists()) {
49- delete()
55+
56+ val numberReg = " \\ d+" .toRegex()
57+ fun isNewerVersion (currentVersion : String , newVersion : String ): Boolean {
58+ val currentParts = numberReg.findAll(currentVersion).map { it.value.toInt() }.toList()
59+ val newParts = numberReg.findAll(newVersion).map { it.value.toInt() }.toList()
60+ val length = maxOf(currentParts.size, newParts.size)
61+ for (i in 0 until length) {
62+ val currentPart = currentParts.getOrNull(i) ? : 0
63+ val newPart = newParts.getOrNull(i) ? : 0
64+ if (currentPart < newPart) {
65+ return true
66+ } else if (currentPart > newPart) {
67+ return false
68+ }
5069 }
70+ return false
5171}
0 commit comments