Note
|
Version 7.0 (and later) of this plugin will only work with JDK 17, Gradle 8.5 and later. |
Based on the used SCM (Source Control Management) this plugin provides project configuration handling and specific
tasks regarding the version handling of the project. The information of the used SCM is identified by special
directories in the project directory ('.git'
). Only Git is full supported and all others uses a file implementation.
But the "file" support is limited.
Git Branches and tags are used for the calculation of the project version.
Note
|
A file-based project does not support the calculation of the version based on previous versions. |
It is also possible to identify the changes between the current working copy and the previous version. This functionality can also be used on a CI server during the creation of a new tag. In this case the changes between two versions are written to a file.
This plugin adds the possibility to calculate version information of a project from the used SCM structure.
It initializes a project property useSCMVersionConfig
. The value of this property is true
, if the plugin was
applied and can be used by the own build logic and other plugins.
This configuration is also working without any remote access, but project specific, because the replacement for
the version information is stored in the build directory of the project. If
<project build dir>/scmversion/static.version
exists and the content is not empty,
the content of this is used for the version.
If the first call of a project task is started with a parameter staticVersion
and a
version information, the file will be created with the version information.
gradlew -PstaticVersion=TRUNKVER publish
This will set the version to TRUNKVER
. The project runs now always with this version.
It is possible to remove this configuration with an empty string for staticVersion
or
if exists with the task clean
.
gradlew -PstaticVersion= publish
The version can be calculated from the local clone without access to the remote repository.
The plugin assumes, that the default branch is called 'master'
.
The plugin detects tags and branches with version information on special prefixes. These prefixes are configured
based on the configuration 'prefixes'
. For parsing, calculation and sorting a library for an extended version object
is used. The library supports version numbers with three or four decimal numbers. Furthermore a special pattern is
supported.
<prefix>_<version>[-<featurebranch name>][-<build extension>]
Therefore branch names must comply with the following patterns. All examples use the default configuration. If no prefix is specified the plugin assumes that the branch is a feature branch. If the version is not part of the branch name, the version is taken from the last tag.
<feature, hotfix or bugfix branch prefix>_<version>-<branch name>
These are the default values
Branch Type | Default value |
---|---|
Feature Branch |
|
Hotfix Branch |
|
Bugfix Branch |
|
The version is the original version of the master/trunk.
FB_1.0.0-JIRA-4711 FB_1.0.0-FeatureBranchName
<stabilization branch prefix>_<version>
The default stabilization branch prefix is 'SB'
. The version is the base version for this branch. In most cases, it is the major version of the master/trunk, before the branch was created.
SB_1 Stabilization branch for version 1.0.0 to 1.X.X SB_1.0 Stabilization branch for version 1.0.0 to 1.0.X
<release prefix>_<version>[-<featurebranch name>][-<build extension>]
The default release prefix is 'RELEASE'
. The version is the base version of the branch. In the most cases, it is the major version of the master/trunk, before the branch was created.
RELEASE_1.1.0 Release tag for version 1.1.0 RELEASE_1.1.0-dev.1 Tag of a development milestone release for version 1.1.0 RELEASE_1.1.0-rc.1 Tag of a release candidate for version 1.1.0 RELEASE_1.0.0-JIRA-4711-dev.1 Tag of a development milestone release of a feature branch version 1.0.0-JIRA-4711
-
Default Branch (master)
The plugin is looking for a tag on the branch. If there is no tag the default value is used and extended withSNAPSHOT
. -
Branch / Feature,Hotfix,Bugfix Branch
The plugin is looking for a tag on the branch. If there is no valid tag on the branch, the version is taken from the name of the branch. The version will be always extended withSNAPSHOT
on the CI server. -
Tags
Without local changes the plugin tries to calculate the name from the tag name.
A checkout of a single commit (detached head) without a tag name will be specially treated. The last found version is
used for the version string. This is extended by the short hash value and 'SNAPSHOT', e.g. 2.0.0-rev.id.ad73b69-SNAPSHOT.
If the environment variable 'CONTINUOUSRELEASE'
or the project variable 'continuousRelease'
is set, the extension SNAPSHOT is not added.
To use the Gradle SCM Version plugin provided by Intershop, include the following in your build script of your root project:
Groovy
plugins {
id 'com.intershop.gradle.scmversion' version '7.0.0'
}
scm {
prefixes {
//default is 'SB'
stabilizationPrefix = 'SBP'
//default is 'FB'
featurePrefix = 'FBP'
//default is 'HB'
hotfixPrefix = 'HBP'
//default is 'BB'
bugfixPrefix = 'BBP'
//default is Release
tagPrefix = 'RBP'
}
version {
type = 'threeDigits'
initialVersion = '1.0.0'
}
changelog {
targetVersion = '1.0.0'
changelogFile = new File(project.buildDir, 'changelog/changelogset.asciidoc')
}
}
version = scm.version.version
Kotlin
plugins {
id("com.intershop.gradle.scmversion") version "7.0.0"
}
scm {
prefixes {
//default is "SB"
stabilizationPrefix = "SBP"
//default is "FB"
featurePrefix = "FBP"
//default is "HB"
hotfixPrefix = "HBP"
//default is "BB"
bugfixPrefix = "BBP"
//default is Release
tagPrefix = "RBP"
}
version {
type = "threeDigits"
initialVersion = "1.0.0"
}
changelog {
previousVersion = "1.0.0"
changelogFile = File(project.buildDir, "changelog/changelogset.asciidoc")
}
}
version = scm.version.version
The Intershop SCM Version plugin adds the following tasks to the project:
Task name | Type | Description |
---|---|---|
showVersion |
ShowVersion |
This task shows the current version of the working copy. |
tag |
CreateTag |
This task creates a tag based on the current working copy. |
branch |
CreateBranch |
This task creates a branch based on the current working copy. |
toVersion |
ToVersion |
This task moves the working copy to a target version.
This version must be specified in a configuration or on the commandline with the paramater |
release |
PrepareRelease |
This task creates a tag, if necessary, and move the the working copy to the version. |
changelog |
CreateChangeLog |
This task creates a change log with all changes between the latest commit of the
current working copy and the previous version. It is possible to specify a 'previous' version with the command line variable |
The tasks tag
, branch
, toVersion
, release
and changelog
can be started with the commandline parameter
--dryRun
. If this parameters is specified no changes on the remote or local repsotiroy will be done. Only
the output will provide information over posible changes.
All task are part of the package 'com.intershop.gradle.scm.task'
This plugin adds an extension scm
to the root project. This extension contains all plugin configurations.
Method | Values | Description |
---|---|---|
user(Closure<ScmUser>) |
This extension is used for the SCM user authentication. |
|
key(Closure<ScmUser>) |
This is also used for the SCM user authentication. |
|
prefixes(Closure<PrefixConfig>) |
This is the extension object for the configuration of branch prefixes. |
|
version(Closure<VersionExtension>) |
This extension contains settings for version calculation and reads properties for the current version and previous version. |
|
changelog(Closure<ChangeLogExtension>) |
This extension contains settings for change log configuration. |
Property | Type | Default value | Description |
---|---|---|---|
user |
This property contains the complete user configuration. |
||
key |
This property contains the complete SSH key configuration. |
||
prefixes |
This is the container for the prefix configuration. |
||
scmType |
ScmType |
This is the value for the identified SCM ( GIT, FILE ) |
|
localService |
ScmLocalService |
This sevices contains all main necessary methods for the working copy. |
|
version |
This is the configuration for the version calculation. |
||
changelog |
This is the configuration for the change log task. |
Property | Type | Default value | Description |
---|---|---|---|
name |
|
'' |
Username or token |
password |
|
'' |
Password |
Property | Type | Default value | Description |
---|---|---|---|
file |
|
|
Private key for SCM authentication |
passphrase |
|
'' |
passphrase for private key |
Property | Type | Default value | Description |
---|---|---|---|
stabilizationPrefix |
|
|
Prefix for stabilization branches |
featurePrefix |
|
|
Prefix for feature branches |
hotfixPrefix |
|
|
Prefix for hotfix branches |
bugfixPrefix |
|
|
Prefix for bugfix branches |
tagPrefix |
|
|
Prefix for release tags |
prefixSeperator |
|
|
Separator between prefix and version |
branchPrefixSeperator |
|
|
Separator between prefix and branch version |
tagPrefixSeperator |
|
|
Separator between prefix and tag version |
Property | Type | Default value | Values | Description |
---|---|---|---|---|
versionService |
|
This service contains methods and properties for the calculation of version objects from the working copy. |
||
type |
|
|
|
The number of used decimal numbers for a version number. |
versionType |
|
read only |
Get the VersionType object from the configured type. |
|
versionExt |
|
'' |
read only |
see description for |
versionBranch |
|
'TAG' |
'TAG' + 'BRANCH' |
Set the version branch configuration of the version calculation. The branch which is primarily used for the version calculation. This can be branch or tag. |
versionBranchType |
|
'BranchType.TAG' |
read only |
This get the calculated BranchType object from versionBranch configuration. |
version |
|
initialVersion |
read only |
Returns the version of the working copy |
previousVersion |
|
'' |
read only |
Returns the previous version of the working copy. |
branchName |
|
'' |
read only |
Returns the branch name only (String after last /) |
increment |
|
|
|
If this property is set, the configured position is used for incrementing the version. |
initialVersion |
|
|
The inital version if a calculation from SCM is not possible. |
|
branchType |
|
|
|
The branch which is primarily used for the version calculation. |
patternDigits |
|
|
|
Determines the number of digit blocks of the version number that will be used for calculating the version filter from branches. |
defaultMetadata |
|
'' |
This is used for releases of feature branches. |
|
useBuildExtension |
|
|
|
Build extension will be removed for SNAPSHOT extensions if this property is false. |
majorVersionOnly |
|
|
This property affects only GIT based repositories. |
|
disableSCM |
|
|
|
If this property is |
disableRevExt |
|
|
|
|
With this configuration the extension of the rev id in special cases can be disabled. It is possible to set this configuration with the environment variable 'SCM_DISABLE_REVIDEXT' or the system or project property 'scmDisableRevIdExt'. |
continuousRelease |
|
|
|
For continuous releases it is helpful to use an version extension with an relation to the source control.
It is possible to enable this configuration also over the environment variable |
continuousReleaseBranches |
|
|
Branchnames |
Property | Type | Default value | Description |
---|---|---|---|
previousVersion |
|
version.previousVersion |
Any version with tag for change log calculation. |
changelogFile |
|
|
The change log will be written to this file. The log file is empty, if the previous version does not exists. |
Method | Values | Description |
---|
plugins {
id 'com.intershop.gradle.scmversion' version '7.0.0'
}
scm {
version {
type = 'threeDigits'
initialVersion = '1.0.0'
}
}
version = scm.version.version
This configuration works for Git [http(s)]. It is necessary to specify username and password for this kind of repositories.
scmUserName = username
scmUserPasswd = password
This configuration works for Git [ssh] with a private key and if necessary with a passphrase. There is no default value for the key.
# without passphrase
scmKeyFile = /user/home/.ssh/id_rsa
# with passphrase
scmKeyFile = /user/home/.ssh/id_rsa
scmKeyPassphrase = passphrase
To use ssh keys you have to switch your repository from https to ssh with the following command:
git remote set-url origin git@gitlab.coporate.com:yourname/yourrepo.git
This configuration can be used when a different version control system is used in the project or another version schema is set in the project.
Note
|
Using this configuration a lot of the features are no longer available. |
plugins {
id 'com.intershop.gradle.scmversion' version '7.0.0'
}
scm {
version {
disableSCM = true
initialVersion = '1.0.0'
}
}
version = scm.version.version
On a CI server some properties must be transfered via the command line:
./gradlew publish -PscmVersionExt=SNAPSHOT
./gradlew publish -PscmVersionExt=RELEASE
Note
|
After a release it is necessary to change the version manually. |
The integration tests use test repositories. Therefore, it is necessary to specify project properties for the test execution.
Test Property | Description | Value |
---|---|---|
giturl |
URL of the test project |
Must be specified with environment variable |
gituser |
User name of Git test user |
Must be specified with environment variable |
gitpasswd |
Password for Git test user |
Must be specified with environment variable |
See here for details.
Copyright 2014-2020 Intershop Communications.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.