-
Notifications
You must be signed in to change notification settings - Fork 89
SemVer Support
In order to support Semantic Versioning, the semver
package provides an implementation of VersionStrategy
that allows inference of the components of a semantic version.
- A semantic version includes 1-3 components:
<normal>[-<pre-release>][+<build metadata>]
- A normal version is the primary component consisting of:
<major>.<minor>.<patch>
- The change scope can be either
MAJOR
,MINOR
, orPATCH
. The scope determines which piece of the normal version will be incremented. - The stage of the change corresponds to the development stage (such as
dev
,milestone
,rc
,final
). Available stages are configured on the strategies set on the plugin extension. - The nearest version is picked from the list of tags that can be parsed as a version. The tag with the fewest number of commits between it and the current
HEAD
(as determined by agit log
) is the nearest.- The nearest any version is the absolute nearest of any tagged versions.
- The nearest normal version is the nearest tagged version that only has a normal component.
The following properties can be specified on the command line (or any other Gradle-supported method) as a way to control which version is inferred at build-time.
release.scope
release.stage
./gradlew release -Prelease.scope=minor -Prelease.stage=rc
Both properties are optional, in general, but may be required by specific strategies.
When strategies are being selected:
- Return
false
, if the project'srelease.stage
property isn't set to one listed in the strategy'sstages
property. - Return
false
, if the repo has uncommitted changes and the strategy hasallowDirtyRepo
to be set tofalse
. - Return
true
.
When a version is inferred:
- Get the scope specified in the
release.scope
property of the project, if set. - Get the stage specified in the
release.stage
property of the project, if set. If it's not set, default to the first stage in the configuredSortedSet
. The first will be the one with the lowest precedence according to SemVer. - Determine the nearest any and nearest normal versions.
- Next the configured partial strategies will be applied in normal, pre-release, and build metadata order.
- If the strategy enforces version precedence the inferred version will be compared against the nearest "any" version. If the inferred version is less than the nearest any, an exception will be thrown.
- The inferred version will be returned.
After gathering the initial state to use during inference, the SemVerStrategy
class delegates to "partial" strategies intended to (but not required to) infer the normal, pre-release, and build metadata components of the version separately.
Multiple strategies can be chained together, if desired, to either:
- Apply all of the chained strategies in order.
- Choose one strategy; the first one that modifies the inference state.
The opinion
package provides a bunch of sample strategies (partial and full) that can be used out of the box or as examples for custom approaches.