Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 93ee16d

Browse files
committed
refactor(build): migrate to java-semver
1 parent e266534 commit 93ee16d

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

build-logic/src/main/kotlin/app/passwordstore/gradle/versioning/VersioningPlugin.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package app.passwordstore.gradle.versioning
88
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
99
import com.android.build.api.variant.VariantOutputConfiguration
1010
import com.android.build.gradle.internal.plugins.AppPlugin
11-
import com.vdurmont.semver4j.Semver
11+
import com.github.zafarkhaja.semver.Version
1212
import java.util.Properties
1313
import java.util.concurrent.atomic.AtomicBoolean
1414
import org.gradle.api.Plugin
@@ -56,30 +56,30 @@ class VersioningPlugin : Plugin<Project> {
5656
}
5757
}
5858
}
59-
val version = Semver(versionName)
59+
val version = Version.parse(versionName)
6060
tasks.register<VersioningTask>("clearPreRelease") {
6161
description = "Remove the pre-release suffix from the version"
62-
semverString.set(version.withClearedSuffix().toString())
62+
semverString.set(version.toStableVersion().toString())
6363
propertyFile.set(propFile)
6464
}
6565
tasks.register<VersioningTask>("bumpMajor") {
6666
description = "Increment the major version"
67-
semverString.set(version.withIncMajor().withClearedSuffix().toString())
67+
semverString.set(version.nextMajorVersion().toString())
6868
propertyFile.set(propFile)
6969
}
7070
tasks.register<VersioningTask>("bumpMinor") {
7171
description = "Increment the minor version"
72-
semverString.set(version.withIncMinor().withClearedSuffix().toString())
72+
semverString.set(version.nextMinorVersion().toString())
7373
propertyFile.set(propFile)
7474
}
7575
tasks.register<VersioningTask>("bumpPatch") {
7676
description = "Increment the patch version"
77-
semverString.set(version.withIncPatch().withClearedSuffix().toString())
77+
semverString.set(version.nextPatchVersion().toString())
7878
propertyFile.set(propFile)
7979
}
8080
tasks.register<VersioningTask>("bumpSnapshot") {
8181
description = "Increment the minor version and add the `SNAPSHOT` suffix"
82-
semverString.set(version.withIncMinor().withSuffix("SNAPSHOT").toString())
82+
semverString.set(version.nextMinorVersion("SNAPSHOT").toString())
8383
propertyFile.set(propFile)
8484
}
8585
afterEvaluate {

build-logic/src/main/kotlin/app/passwordstore/gradle/versioning/VersioningTask.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
package app.passwordstore.gradle.versioning
77

8-
import com.vdurmont.semver4j.Semver
8+
import com.github.zafarkhaja.semver.Version
99
import org.gradle.api.DefaultTask
1010
import org.gradle.api.file.RegularFileProperty
1111
import org.gradle.api.provider.Property
@@ -21,11 +21,11 @@ abstract class VersioningTask : DefaultTask() {
2121
@get:OutputFile abstract val propertyFile: RegularFileProperty
2222

2323
/** Generate the Android 'versionCode' property */
24-
private fun Semver.androidCode(): Int {
25-
return major * 1_00_00 + minor * 1_00 + patch
24+
private fun Version.androidCode(): Long {
25+
return majorVersion() * 1_00_00 + minorVersion() * 1_00 + patchVersion()
2626
}
2727

28-
private fun Semver.toPropFileText(): String {
28+
private fun Version.toPropFileText(): String {
2929
val newVersionCode = androidCode()
3030
val newVersionName = toString()
3131
return buildString {
@@ -45,6 +45,6 @@ abstract class VersioningTask : DefaultTask() {
4545

4646
@TaskAction
4747
fun execute() {
48-
propertyFile.get().asFile.writeText(Semver(semverString.get()).toPropFileText())
48+
propertyFile.get().asFile.writeText(Version.parse(semverString.get()).toPropFileText())
4949
}
5050
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ build-moshi = { module = "com.squareup.moshi:moshi", version.ref = "moshi" }
4848
build-moshi-kotlin = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshi" }
4949
build-okhttp = "com.squareup.okhttp3:okhttp:4.12.0"
5050
build-r8 = "com.android.tools:r8:8.3.37"
51-
build-semver = "com.vdurmont:semver4j:3.1.0"
51+
build-semver = "com.github.zafarkhaja:java-semver:0.10.2"
5252
build-sentry = "io.sentry.android.gradle:io.sentry.android.gradle.gradle.plugin:4.3.1"
5353
compose-bom = "androidx.compose:compose-bom:2024.03.00"
5454
compose-foundation-core = { module = "androidx.compose.foundation:foundation" }

0 commit comments

Comments
 (0)