From 9c61fbaa4ef7254148a7e69cfe630dc908d6671c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Mong=C3=A5rd?= Date: Tue, 19 Aug 2025 13:39:44 +0200 Subject: [PATCH 1/4] build: Kotlin JVM toolchain config --- build.gradle.kts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 03b4b1f..39cab04 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,6 +13,10 @@ plugins { id("jacoco") } +kotlin { + jvmToolchain(17) +} + semver { releaseTagNameFormat = "v%s" createReleaseTag = false From e376836dbef481bca12ea443da975980d83e9dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Mong=C3=A5rd?= Date: Mon, 1 Sep 2025 23:31:00 +0200 Subject: [PATCH 2/4] feat: added possibility to output two digit version format --- README.md | 46 +++++++++++++++++++ .../plugin/gradle/GitSemverPluginExtension.kt | 7 +-- .../git/semver/plugin/semver/BaseSettings.kt | 6 ++- .../semver/plugin/semver/MutableSemVersion.kt | 43 ++++++++++++----- .../semver/plugin/semver/SemInfoVersion.kt | 12 ++++- .../git/semver/plugin/semver/SemVersion.kt | 9 +++- .../git/semver/plugin/semver/VersionFinder.kt | 4 +- .../plugin/semver/MutableSemVersionTest.kt | 35 ++++++++++++++ 8 files changed, 139 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index f57f996..67aecb5 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,50 @@ string will not be semver compliant. * semver.infoVersion == semver.semVersion.toInfoVersionString("%03d", 0, true, false) * semver.semVersion.toString() == semver.semVersion.toInfoVersionString("%03d", 7, true, false) +### Two-Digit Versioning + +The plugin supports 2-digit versioning (major.minor) in addition to the standard 3-digit semantic versioning (major.minor.patch). +This can be useful for projects that follow a simpler versioning scheme. + +To enable 2-digit versioning, set `useTwoDigitVersion = true` in your configuration: + +```groovy +semver { + useTwoDigitVersion = true +} +``` + +#### How 2-Digit Versioning Works + +When `useTwoDigitVersion` is enabled: + +* **Version Format**: Versions are formatted as `major.minor` (e.g., `5.2` instead of `5.2.0`) +* **Patch Changes**: Fix commits (`fix:`) are treated as minor version changes instead of patch changes +* **Version Bumping**: When no specific version changes are triggered, the minor version is incremented instead of the patch version +* **Pre-releases**: Pre-release versions work the same way (e.g., `5.2-alpha.1`) + +#### Example with 2-Digit Versioning + +| Command | Commit Text | Calculated version | +| --------------------------------------------- | ------------------------- | ------------------- | +| git commit -m "Initial commit" | Initial commit | 0.1-SNAPSHOT+001 | +| git commit -m "fix: a bug fix" | fix: a bug fix | 0.2-SNAPSHOT+001 | +| gradle releaseVersion | release: v0.2 | 0.2 | +| git commit -m "feat: new feature" | feat: new feature | 0.3-SNAPSHOT+001 | +| git commit -m "feat!: breaking change" | feat!: breaking change | 1.0-SNAPSHOT+002 | +| gradle releaseVersion --preRelease="alpha.1" | release: v1.0-alpha.1 | 1.0-alpha.1 | + +#### Accessing 2-Digit Versions + +When `useTwoDigitVersion` is enabled, the standard version properties automatically use the 2-digit format: + +* `semver.version` - Returns the 2-digit version (e.g., `5.2`) +* `semver.infoVersion` - Returns the 2-digit version with commit count (e.g., `5.2+001`) +* `semver.semVersion.toString()` - Returns the 2-digit version with SHA (e.g., `5.2+001.sha.1c792d5`) + +You can also access the 2-digit version explicitly using: + +* `semver.twoDigitVersion` - Always returns the 2-digit format regardless of the setting ## Tasks @@ -259,6 +303,7 @@ semver { gitDirectory = project.projectDir createReleaseCommit = true createReleaseTag = true + useTwoDigitVersion = false } //Remember to retrieve the version after plugin has been configured @@ -286,6 +331,7 @@ version = semver.version has the same effect as the --no-tag flag. * **createReleaseCommit**: If a release commit should be created when running the release task. Setting this to false has the same effect as the --no-commit flag. +* **useTwoDigitVersion**: If the version should be two digits instead of three. Patterns is matched using [java regular expressions](https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html) with IGNORE_CASE and MULTILINE options enabled. diff --git a/src/main/kotlin/git/semver/plugin/gradle/GitSemverPluginExtension.kt b/src/main/kotlin/git/semver/plugin/gradle/GitSemverPluginExtension.kt index 30083e5..376191f 100644 --- a/src/main/kotlin/git/semver/plugin/gradle/GitSemverPluginExtension.kt +++ b/src/main/kotlin/git/semver/plugin/gradle/GitSemverPluginExtension.kt @@ -6,11 +6,8 @@ import git.semver.plugin.semver.SemInfoVersion import git.semver.plugin.semver.SemVersion import git.semver.plugin.semver.SemverSettings import org.gradle.api.Project -import org.gradle.api.file.Directory import org.gradle.api.file.DirectoryProperty -import org.gradle.api.provider.Provider import org.gradle.api.provider.ProviderFactory -import org.gradle.api.tasks.Internal abstract class GitSemverPluginExtension(project: Project, providerFactory: ProviderFactory) : BaseSettings() { @@ -102,7 +99,7 @@ abstract class GitSemverPluginExtension(project: Project, providerFactory: Provi /** * The semantic version for the project with commit info excluding sha as a string e.g. "1.2.3-Alpha.4+005" */ - val infoVersion: String by lazy { semVersion.toInfoVersionString() } + val infoVersion: String by lazy { semVersion.toInfoVersionString(useTwoDigitVersion = useTwoDigitVersion) } /** * The semantic version for the project e.g. 1.2.3-Alpha.4 @@ -113,7 +110,7 @@ abstract class GitSemverPluginExtension(project: Project, providerFactory: Provi /** * The semantic version for the project as a string e.g. "1.2.3-Alpha.4" */ - val version: String by lazy { versionValue.toString() } + val version: String by lazy { versionValue.toString(useTwoDigitVersion) } private var semInfoVersionValueSource = project.providers.of(SemInfoVersionValueSource::class.java) { it.parameters.getGitDir().set(gitDirectory); diff --git a/src/main/kotlin/git/semver/plugin/semver/BaseSettings.kt b/src/main/kotlin/git/semver/plugin/semver/BaseSettings.kt index 244ac72..e1ed1e3 100644 --- a/src/main/kotlin/git/semver/plugin/semver/BaseSettings.kt +++ b/src/main/kotlin/git/semver/plugin/semver/BaseSettings.kt @@ -13,11 +13,13 @@ abstract class BaseSettings( var groupVersionIncrements: Boolean = true, var noDirtyCheck: Boolean = false, var noAutoBump: Boolean = false, - var gitSigning: Boolean? = null // null means use the jgit default + var gitSigning: Boolean? = null, // null means use the jgit default + var useTwoDigitVersion: Boolean = false // Enable 2-digit versioning (major.minor) instead of 3-digit (major.minor.patch) ) : Serializable { constructor(settings: BaseSettings) : this( settings.defaultPreRelease, settings.releasePattern, settings.patchPattern, settings.minorPattern, settings.majorPattern, settings.releaseCommitTextFormat, settings.releaseTagNameFormat, - settings.groupVersionIncrements, settings.noDirtyCheck, settings.noAutoBump + settings.groupVersionIncrements, settings.noDirtyCheck, settings.noAutoBump, settings.gitSigning, + settings.useTwoDigitVersion ) } \ No newline at end of file diff --git a/src/main/kotlin/git/semver/plugin/semver/MutableSemVersion.kt b/src/main/kotlin/git/semver/plugin/semver/MutableSemVersion.kt index 985ba3d..24ca944 100644 --- a/src/main/kotlin/git/semver/plugin/semver/MutableSemVersion.kt +++ b/src/main/kotlin/git/semver/plugin/semver/MutableSemVersion.kt @@ -113,19 +113,21 @@ internal class MutableSemVersion( ) { when { major > 0 && settings.majorRegex.containsMatchIn(text) -> - if (!isPreRelease || major == initialVersion.major) { - bumpMajor += 1 - bumpMinor = 0 - bumpPatch = 0 - bumpPre = 0 + bumpMajor() + + settings.useTwoDigitVersion -> + if (settings.minorRegex.containsMatchIn(text) || + settings.patchRegex.containsMatchIn(text) + ) { + if (preRelease.number == null) { + bumpMinor() + } else { + bumpPre += 1 + } } settings.minorRegex.containsMatchIn(text) -> - if (!isPreRelease || major == initialVersion.major && minor == initialVersion.minor) { - bumpMinor += 1 - bumpPatch = 0 - bumpPre = 0 - } + bumpMinor() settings.patchRegex.containsMatchIn(text) -> if (preRelease.number == null) { @@ -137,7 +139,24 @@ internal class MutableSemVersion( } } - internal fun applyPendingChanges(forceBumpIfNoChanges: Boolean, groupChanges: Boolean): Boolean { + private fun bumpMajor() { + if (!isPreRelease || major == initialVersion.major) { + bumpMajor += 1 + bumpMinor = 0 + bumpPatch = 0 + bumpPre = 0 + } + } + + private fun bumpMinor() { + if (!isPreRelease || major == initialVersion.major && minor == initialVersion.minor) { + bumpMinor += 1 + bumpPatch = 0 + bumpPre = 0 + } + } + + internal fun applyPendingChanges(forceBumpIfNoChanges: Boolean, groupChanges: Boolean, useTwoDigitVersion: Boolean = false): Boolean { if (hasPendingChanges) { if (groupChanges) { applyChangesGrouped() @@ -155,6 +174,8 @@ internal class MutableSemVersion( val preReleaseNumber = preRelease.number if (preReleaseNumber != null) { preRelease = preRelease.copy(number = preReleaseNumber + 1) + } else if (useTwoDigitVersion) { + minor += 1 } else { patch += 1 } diff --git a/src/main/kotlin/git/semver/plugin/semver/SemInfoVersion.kt b/src/main/kotlin/git/semver/plugin/semver/SemInfoVersion.kt index 233b492..e7fac4e 100644 --- a/src/main/kotlin/git/semver/plugin/semver/SemInfoVersion.kt +++ b/src/main/kotlin/git/semver/plugin/semver/SemInfoVersion.kt @@ -23,9 +23,13 @@ data class SemInfoVersion( commitCountStringFormat: String = "%03d", shaLength: Int = 0, v2: Boolean = true, - appendPreReleaseLast: Boolean = false + appendPreReleaseLast: Boolean = false, + useTwoDigitVersion: Boolean = false ): String { - val builder = StringBuilder().append(major).append('.').append(minor).append('.').append(patch) + val builder = StringBuilder().append(major).append('.').append(minor) + if (!useTwoDigitVersion) { + builder.append('.').append(patch) + } if (v2) { if (isPreRelease && !appendPreReleaseLast) { builder.append('-').append(preRelease) @@ -54,6 +58,10 @@ data class SemInfoVersion( return toInfoVersionString(shaLength = 7) } + fun toString(useTwoDigitVersion: Boolean): String { + return toInfoVersionString(useTwoDigitVersion = useTwoDigitVersion, shaLength = 7) + } + fun revisionString(): String { return "${previousVersion.major}.${previousVersion.minor}.${previousVersion.patch}.$commitCount" } diff --git a/src/main/kotlin/git/semver/plugin/semver/SemVersion.kt b/src/main/kotlin/git/semver/plugin/semver/SemVersion.kt index 952c285..ddf12f5 100644 --- a/src/main/kotlin/git/semver/plugin/semver/SemVersion.kt +++ b/src/main/kotlin/git/semver/plugin/semver/SemVersion.kt @@ -10,7 +10,14 @@ data class SemVersion( ) : Serializable, Version { override fun toString(): String { - val builder = StringBuilder().append(major).append('.').append(minor).append('.').append(patch) + return toString(false) + } + + fun toString(useTwoDigitVersion: Boolean): String { + val builder = StringBuilder().append(major).append('.').append(minor) + if (!useTwoDigitVersion) { + builder.append('.').append(patch) + } if (isPreRelease) { builder.append('-').append(preRelease) } diff --git a/src/main/kotlin/git/semver/plugin/semver/VersionFinder.kt b/src/main/kotlin/git/semver/plugin/semver/VersionFinder.kt index 32ac7e8..3e014e2 100644 --- a/src/main/kotlin/git/semver/plugin/semver/VersionFinder.kt +++ b/src/main/kotlin/git/semver/plugin/semver/VersionFinder.kt @@ -11,7 +11,7 @@ class VersionFinder(private val settings: SemverSettings, private val tags: Map< fun getVersion(commit: Commit, isClean: Boolean, defaultPreRelease: String?): SemInfoVersion { val semVersion = findVersion(commit) val isModified = semVersion.commitCount > 0 || !isClean - val updated = semVersion.applyPendingChanges(isModified && !settings.noAutoBump, settings.groupVersionIncrements) + val updated = semVersion.applyPendingChanges(isModified && !settings.noAutoBump, settings.groupVersionIncrements, settings.useTwoDigitVersion) if (!semVersion.isPreRelease && updated) { semVersion.setPreRelease(PreRelease.parse(defaultPreRelease)) @@ -22,7 +22,7 @@ class VersionFinder(private val settings: SemverSettings, private val tags: Map< fun getReleaseVersion(commit: Commit, newPreRelease: String?): SemInfoVersion { val semVersion = findVersion(commit) semVersion.commitCount = 0 - semVersion.applyPendingChanges(!semVersion.isPreRelease || "" != newPreRelease, settings.groupVersionIncrements) + semVersion.applyPendingChanges(!semVersion.isPreRelease || "" != newPreRelease, settings.groupVersionIncrements, settings.useTwoDigitVersion) if (newPreRelease != null) { semVersion.setPreRelease(PreRelease.parse(newPreRelease)) diff --git a/src/test/kotlin/git/semver/plugin/semver/MutableSemVersionTest.kt b/src/test/kotlin/git/semver/plugin/semver/MutableSemVersionTest.kt index afc392a..9b6ee4e 100644 --- a/src/test/kotlin/git/semver/plugin/semver/MutableSemVersionTest.kt +++ b/src/test/kotlin/git/semver/plugin/semver/MutableSemVersionTest.kt @@ -124,4 +124,39 @@ class MutableSemVersionTest { .isEqualTo("1.2.3+sha.8727a3e-SNAPSHOT") } + @Test + fun `test two digit version parsing`() { + val version = MutableSemVersion.tryParse(Tag("5.2", SHA)) + assertThat(version).isNotNull() + assertThat(version?.major).isEqualTo(5) + assertThat(version?.minor).isEqualTo(2) + assertThat(version?.patch).isEqualTo(0) + assertThat(version?.toSemInfoVersion()?.toSemVersion()?.toString(true)).isEqualTo("5.2") + } + + @Test + fun `test two digit version with pre-release`() { + val version = MutableSemVersion.tryParse(Tag("5.2-alpha.1", SHA)) + assertThat(version).isNotNull() + assertThat(version?.major).isEqualTo(5) + assertThat(version?.minor).isEqualTo(2) + assertThat(version?.patch).isEqualTo(0) + assertThat(version?.toSemInfoVersion()?.toSemVersion()?.toString(true)).isEqualTo("5.2-alpha.1") + } + + @Test + fun `test two digit version bumping`() { + val settings = SemverSettings() + settings.useTwoDigitVersion = true + + val semver = MutableSemVersion.tryParse(Tag("5.2", SHA))!! + val commit = Commit("fix: a fix", SHA, 0, emptySequence()) + + // In 2-digit mode, fix commits should bump minor version + semver.updateFromCommit(commit, settings, null) + semver.applyPendingChanges(false, true, true) + + assertThat(semver.toSemInfoVersion().toSemVersion().toString(true)).isEqualTo("5.3") + } + } \ No newline at end of file From 2fe295104a17fe4b48100cd41558d7d2e2e98fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Mong=C3=A5rd?= Date: Mon, 1 Sep 2025 23:35:24 +0200 Subject: [PATCH 3/4] docs(README): improved the documentation --- README.md | 65 ++++++++++++++++++++++--------------------------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 67aecb5..33eaa1a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# Semantic versioning for Gradle using Git +# Git Semantic Versioning Plugin for Gradle [![Gradle Build](https://github.com/jmongard/Git.SemVersioning.Gradle/workflows/Gradle%20Build/badge.svg)](https://github.com/jmongard/Git.SemVersioning.Gradle/actions/workflows/gradle-push.yml) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=jmongard_Git.SemVersioning.Gradle&metric=alert_status)](https://sonarcloud.io/dashboard?id=jmongard_Git.SemVersioning.Gradle) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=jmongard_Git.SemVersioning.Gradle&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=jmongard_Git.SemVersioning.Gradle) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=jmongard_Git.SemVersioning.Gradle&metric=coverage)](https://sonarcloud.io/summary/new_code?id=jmongard_Git.SemVersioning.Gradle) [![GitHub tag (with filter)](https://img.shields.io/github/v/tag/jmongard/Git.SemVersioning.Gradle?logo=gradle&label=Release)](https://plugins.gradle.org/plugin/com.github.jmongard.git-semver-plugin) -Gradle plugin for automatically versioning a project using semantic versioning and conventional commits with change log support based on git commit messages. +A Gradle plugin that automatically versions your project using semantic versioning and conventional commits. It analyzes Git commit messages to determine version increments and generates change logs based on your commit history. ## Usage @@ -38,18 +38,13 @@ The plugin requires java version 17 to run. (Use version `0.13.0` if Java 8 is r ## Versioning -The versioning system is designed to follow semantic versioning as described by https://semver.org/. +The versioning system follows semantic versioning as described at [semver.org](https://semver.org/). -It works by recursively traversing the commit tree until it finds a version tag or release commit and then calculating -the new version using from there using commit messages. +The plugin works by traversing the Git commit history backwards from HEAD until it finds a version tag or release commit, then calculates the new version based on conventional commit messages since that point. -The plugin will look for [conventional commit](https://www.conventionalcommits.org/) messages (`fix:`, `feat:`, `refactor!:`, ...) -and will increase the corresponding version number. +The plugin recognizes [conventional commit](https://www.conventionalcommits.org/) messages (`fix:`, `feat:`, `refactor!:`, etc.) and increments the corresponding version number accordingly. -The plugin has the opinion that you want to group several fixes/features or breaking changes into a single release. -Therefore, the major, minor or patch number will be increases by at most one compared to the previous release that is -not a pre-release version. Set property `groupVersionIncrements = false` if you don't want the version changes to be combined. -(See [Configuration](#Configuration) reference below.) +By default, the plugin groups multiple fixes/features or breaking changes into a single release. This means the major, minor, or patch number will increase by at most one compared to the previous release (excluding pre-releases). Set `groupVersionIncrements = false` if you prefer each commit to increment the version individually. ### Releases @@ -62,12 +57,11 @@ The version number should consist of three numbers separated by a dot e.g. `1.0. be at the start of the message e.g. `release: v1.2.3` will be matched. -### Uncommited changes or non release commits +### Uncommitted Changes -If no version changed has been triggered by any commit messages since the last release -then the patch number will be increased by one. +If no version increment has been triggered by conventional commit messages since the last release, the patch number will be increased by one to indicate development progress. -If the current version is not a pre-release then `-SNAPSHOT` will be added. +If the current version is not already a pre-release, `-SNAPSHOT` will be appended to indicate this is a development version. ## Version format @@ -138,10 +132,6 @@ When `useTwoDigitVersion` is enabled, the standard version properties automatica * `semver.infoVersion` - Returns the 2-digit version with commit count (e.g., `5.2+001`) * `semver.semVersion.toString()` - Returns the 2-digit version with SHA (e.g., `5.2+001.sha.1c792d5`) -You can also access the 2-digit version explicitly using: - -* `semver.twoDigitVersion` - Always returns the 2-digit format regardless of the setting - ## Tasks ## `printVersion` @@ -168,7 +158,7 @@ $ gradlew printInfoVersion ## `printSemVersion` This plugin adds a printSemVersion task, which will echo the project's calculated version -to standard-out includning commit count and sha. +to standard-out including commit count and SHA. ````shell $ gradlew printSemVersion @@ -178,13 +168,12 @@ $ gradlew printSemVersion ```` ## `printChangeLog` -This plugin adds a printChangeLog task, which will format the commit message for the current version -and output them to standard-out. To avoid enoding problem in the console the change log can be outputed -to an UTF-8 encoded file using `--file ` e.g. `./gradlew printChangeLog --file build/changelog.md` -Note: Use an absolute path for filename as the working directory might not be the one you expect if running -using gradle deamon. +This plugin adds a printChangeLog task, which will format the commit messages for the current version +and output them to standard-out. To avoid encoding problems in the console, the change log can be output +to a UTF-8 encoded file using `--file `, e.g. `./gradlew printChangeLog --file build/changelog.md`. -Note: The `printChangeLog` task is currently only registered on the root project given that the plugin is applied there. +**Note:** Use an absolute path for the filename as the working directory might not be what you expect when running +using the Gradle daemon. The `printChangeLog` task is currently only registered on the root project when the plugin is applied there. ````shell $ gradlew printChangeLog @@ -202,19 +191,17 @@ $ gradlew printChangeLog [Configuring the changelog](/ChangeLog.md) ## `releaseVersion` -The `releaseVersion` task will by default create both a release commit, and a release tag. The releaseVersion task will -fail with an error if there exists local modification. It is possible to change this behaviour with the following options: +The `releaseVersion` task creates both a release commit and a release tag by default. The task will fail with an error if there are uncommitted local modifications. You can modify this behavior using the following options: - * **--no-tag**: skip creating a tag. (Can also be set in settings using `createReleaseTag=false`.) - * **--tag**: create a tag (If this has been disabled by the `createReleaseTag=false` option otherwise this is the default.) - * **--no-commit**: skip creating a commit. (Can also be set in settings using `createReleaseCommit=false`.) - * **--commit**: create a commit (If this has been disabled by the `createReleaseCommit=false` option otherwise this is the default.) - * **--no-dirty**: skip dirty check. (Can also be set in settings using `noDirtyCheck=true`.) - * **--message**="a message": Add a message text to the tag and/or commit - * **--preRelease**="pre-release": Change the current pre-release e.g. `--preRelease=alpha.1`. - Set the pre-release to "-" e.g. `--preRelease=-` to promote a pre-release to a release. +* **--no-tag**: Skip creating a tag (can also be set in settings using `createReleaseTag=false`) +* **--tag**: Create a tag (default behavior, unless disabled in settings) +* **--no-commit**: Skip creating a commit (can also be set in settings using `createReleaseCommit=false`) +* **--commit**: Create a commit (default behavior, unless disabled in settings) +* **--no-dirty**: Skip the dirty working directory check (can also be set in settings using `noDirtyCheck=true`) +* **--message**="message": Add a custom message to the tag and/or commit +* **--preRelease**="version": Set the pre-release identifier (e.g., `--preRelease=alpha.1`). Use `--preRelease=-` to promote a pre-release to a full release -Note: The `releaseVersion` task is currently only registered on the root project given that the plugin is applied there. +**Note:** The `releaseVersion` task is currently only registered on the root project when the plugin is applied there. ## Example of how version is calculated With setting: `groupVersionIncrements = true` (default) @@ -320,7 +307,7 @@ version = semver.version version tags with "v". * **groupVersionIncrements**: Used to disable grouping of version increments so that each commit message counts. * **noDirtyCheck**: Can be used to ignore all local modifications when calculating the version. - Disabling dirty check can also be donne from the command line e.g. `gradlew -PnoDirtyCheck=true someOtherTask`. + Disabling dirty check can also be done from the command line e.g. `gradlew -PnoDirtyCheck=true someOtherTask`. * **noAutoBump**: If set only commits matching majorPattern, minorPattern or patchPattern will increase the version. The default behaviour for the plugin is to assume you have begun the work on the next release for any commit you do after the last release. The patch level (or pre-release level, if the last release was a pre-release) of the version @@ -340,7 +327,7 @@ with IGNORE_CASE and MULTILINE options enabled. This plugin has been tested on Gradle 7.x and 8.x. (Version 0.4.3 and older should work on gradle 6.x and probably 5.x) -## Continues Integration +## Continuous Integration The plugin calculates the version using the commit tree. Make sure you check out all commits relevant and not just a shallow copy. From af42551dc46fd17b61afce6937d8b45e1cad7cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Mong=C3=A5rd?= Date: Sun, 23 Nov 2025 09:05:57 +0100 Subject: [PATCH 4/4] refactor: improve code --- .../kotlin/git/semver/plugin/semver/MutableSemVersion.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/git/semver/plugin/semver/MutableSemVersion.kt b/src/main/kotlin/git/semver/plugin/semver/MutableSemVersion.kt index 24ca944..5a84c8e 100644 --- a/src/main/kotlin/git/semver/plugin/semver/MutableSemVersion.kt +++ b/src/main/kotlin/git/semver/plugin/semver/MutableSemVersion.kt @@ -167,10 +167,14 @@ internal class MutableSemVersion( return true } - if (!forceBumpIfNoChanges) { - return false + if (forceBumpIfNoChanges) { + forceBump(useTwoDigitVersion) + return true } + return false + } + private fun forceBump(useTwoDigitVersion: Boolean) { val preReleaseNumber = preRelease.number if (preReleaseNumber != null) { preRelease = preRelease.copy(number = preReleaseNumber + 1) @@ -179,7 +183,6 @@ internal class MutableSemVersion( } else { patch += 1 } - return true } private fun applyChangesNotGrouped() {