You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Added the option to use two digit version (#81)
* build: Kotlin JVM toolchain config
* feat: added possibility to output two digit version format
* docs(README): improved the documentation
* refactor: improve code
---------
Co-authored-by: Joel Mongård <joel.mongard@idainfront.se>
[](https://sonarcloud.io/summary/new_code?id=jmongard_Git.SemVersioning.Gradle)
[](https://plugins.gradle.org/plugin/com.github.jmongard.git-semver-plugin)
7
7
8
-
Gradle plugin for automatically versioning a project using semantic versioning and conventional commits with change log support based on git commit messages.
8
+
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.
9
9
10
10
11
11
## Usage
@@ -38,18 +38,13 @@ The plugin requires Gradle 8 and Java version 17 to run.
38
38
39
39
## Versioning
40
40
41
-
The versioning system is designed to follow semantic versioning as described by https://semver.org/.
41
+
The versioning system follows semantic versioning as described at [semver.org](https://semver.org/).
42
42
43
-
It works by recursively traversing the commit tree until it finds a version tag or release commit and then calculating
44
-
the new version using from there using commit messages.
43
+
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.
45
44
46
-
The plugin will look for [conventional commit](https://www.conventionalcommits.org/) messages (`fix:`, `feat:`, `refactor!:`, ...)
47
-
and will increase the corresponding version number.
45
+
The plugin recognizes [conventional commit](https://www.conventionalcommits.org/) messages (`fix:`, `feat:`, `refactor!:`, etc.) and increments the corresponding version number accordingly.
48
46
49
-
The plugin has the opinion that you want to group several fixes/features or breaking changes into a single release.
50
-
Therefore, the major, minor or patch number will be increases by at most one compared to the previous release that is
51
-
not a pre-release version. Set property `groupVersionIncrements = false` if you don't want the version changes to be combined.
52
-
(See [Configuration](#Configuration) reference below.)
47
+
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.
53
48
54
49
### Releases
55
50
@@ -62,12 +57,11 @@ The version number should consist of three numbers separated by a dot e.g. `1.0.
62
57
be at the start of the message e.g. `release: v1.2.3` will be matched.
63
58
64
59
65
-
### Uncommited changes or non release commits
60
+
### Uncommitted Changes
66
61
67
-
If no version changed has been triggered by any commit messages since the last release
68
-
then the patch number will be increased by one.
62
+
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.
69
63
70
-
If the current version is not a pre-release then `-SNAPSHOT` will be added.
64
+
If the current version is not already a pre-release, `-SNAPSHOT` will be appended to indicate this is a development version.
71
65
72
66
73
67
## Version format
@@ -97,6 +91,46 @@ string will not be semver compliant.
When `useTwoDigitVersion` is enabled, the standard version properties automatically use the 2-digit format:
130
+
131
+
*`semver.version` - Returns the 2-digit version (e.g., `5.2`)
132
+
*`semver.infoVersion` - Returns the 2-digit version with commit count (e.g., `5.2+001`)
133
+
*`semver.semVersion.toString()` - Returns the 2-digit version with SHA (e.g., `5.2+001.sha.1c792d5`)
100
134
101
135
## Tasks
102
136
@@ -124,7 +158,7 @@ $ gradlew printInfoVersion
124
158
125
159
## `printSemVersion`
126
160
This plugin adds a printSemVersion task, which will echo the project's calculated version
127
-
to standard-out includning commit count and sha.
161
+
to standard-out including commit count and SHA.
128
162
129
163
````shell
130
164
$ gradlew printSemVersion
@@ -134,13 +168,12 @@ $ gradlew printSemVersion
134
168
````
135
169
136
170
## `printChangeLog`
137
-
This plugin adds a printChangeLog task, which will format the commit message for the current version
138
-
and output them to standard-out. To avoid enoding problem in the console the change log can be outputed
139
-
to an UTF-8 encoded file using `--file <filename>` e.g. `./gradlew printChangeLog --file build/changelog.md`
140
-
Note: Use an absolute path for filename as the working directory might not be the one you expect if running
141
-
using gradle deamon.
171
+
This plugin adds a printChangeLog task, which will format the commit messages for the current version
172
+
and output them to standard-out. To avoid encoding problems in the console, the change log can be output
173
+
to a UTF-8 encoded file using `--file <filename>`, e.g. `./gradlew printChangeLog --file build/changelog.md`.
142
174
143
-
Note: The `printChangeLog` task is currently only registered on the root project given that the plugin is applied there.
175
+
**Note:** Use an absolute path for the filename as the working directory might not be what you expect when running
176
+
using the Gradle daemon. The `printChangeLog` task is currently only registered on the root project when the plugin is applied there.
144
177
145
178
````shell
146
179
$ gradlew printChangeLog
@@ -158,19 +191,17 @@ $ gradlew printChangeLog
158
191
[Configuring the changelog](/ChangeLog.md)
159
192
160
193
## `releaseVersion`
161
-
The `releaseVersion` task will by default create both a release commit, and a release tag. The releaseVersion task will
162
-
fail with an error if there exists local modification. It is possible to change this behaviour with the following options:
194
+
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:
163
195
164
-
***--no-tag**: skip creating a tag. (Can also be setin settings using `createReleaseTag=false`.)
165
-
***--tag**: create a tag (If this has been disabled by the `createReleaseTag=false` option otherwise this is the default.)
166
-
***--no-commit**: skip creating a commit. (Can also be setin settings using `createReleaseCommit=false`.)
167
-
***--commit**: create a commit (If this has been disabled by the `createReleaseCommit=false` option otherwise this is the default.)
168
-
***--no-dirty**: skip dirty check. (Can also be setin settings using `noDirtyCheck=true`.)
169
-
***--message**="a message": Add a message text to the tag and/or commit
170
-
***--preRelease**="pre-release": Change the current pre-release e.g. `--preRelease=alpha.1`.
171
-
Set the pre-release to "-" e.g. `--preRelease=-` to promote a pre-release to a release.
196
+
***--no-tag**: Skip creating a tag (can also be setin settings using `createReleaseTag=false`)
197
+
***--tag**: Create a tag (default behavior, unless disabled in settings)
198
+
***--no-commit**: Skip creating a commit (can also be setin settings using `createReleaseCommit=false`)
199
+
***--commit**: Create a commit (default behavior, unless disabled in settings)
200
+
***--no-dirty**: Skip the dirty working directory check (can also be setin settings using `noDirtyCheck=true`)
201
+
***--message**="message": Add a custom message to the tag and/or commit
202
+
***--preRelease**="version": Set the pre-release identifier (e.g., `--preRelease=alpha.1`). Use `--preRelease=-` to promote a pre-release to a full release
172
203
173
-
Note: The `releaseVersion` task is currently only registered on the root project given that the plugin is applied there.
204
+
**Note:** The `releaseVersion` task is currently only registered on the root project when the plugin is applied there.
174
205
175
206
## Example of how version is calculated
176
207
With setting: `groupVersionIncrements = true` (default)
@@ -260,6 +291,7 @@ semver {
260
291
createReleaseCommit = true
261
292
createReleaseTag = true
262
293
metaSeparator = '+'
294
+
useTwoDigitVersion = false
263
295
}
264
296
265
297
//Remember to retrieve the version after plugin has been configured
@@ -276,7 +308,7 @@ version = semver.version
276
308
version tags with "v".
277
309
***groupVersionIncrements**: Used to disable grouping of version increments so that each commit message counts.
278
310
***noDirtyCheck**: Can be used to ignore all local modifications when calculating the version.
279
-
Disabling dirty check can also be donne from the command line e.g. `gradlew -PnoDirtyCheck=true someOtherTask`.
311
+
Disabling dirty check can also be done from the command line e.g. `gradlew -PnoDirtyCheck=true someOtherTask`.
280
312
***noAutoBump**: If set only commits matching majorPattern, minorPattern or patchPattern will increase the version.
281
313
The default behaviour for the plugin is to assume you have begun the work on the next release for any commit you do
282
314
after the last release. The patch level (or pre-release level, if the last release was a pre-release) of the version
@@ -288,6 +320,7 @@ version = semver.version
288
320
***createReleaseCommit**: If a release commit should be created when running the release task. Setting this to false
289
321
has the same effect as the --no-commit flag.
290
322
***metaSeparator**: The character to use to separate build metadata from the version when printing info version.
323
+
***useTwoDigitVersion**: If the version should be two digits instead of three.
291
324
292
325
Patterns is matched using [java regular expressions](https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)
293
326
with IGNORE_CASE and MULTILINE options enabled.
@@ -296,7 +329,7 @@ with IGNORE_CASE and MULTILINE options enabled.
296
329
297
330
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)
298
331
299
-
## Continues Integration
332
+
## Continuous Integration
300
333
The plugin calculates the version using the commit tree. Make sure you check out all commits relevant and not just
0 commit comments