Note
|
Version 3.4 (and later) of this plugin will only work with JDK 8, Gradle 4.4 and later. Version 3.3 can be used for Gradle 4.4 and previous version of Gradle 4. |
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'
, '.svn'
).
The plugin supports the following SCMs:
-
git
-
svn
-
file (limited functionality)
Branches and tags are used for the calculation of the project version. The basic functionality for Git and Subversion is the same.
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 implementation depends on SVNKit 1.8. Therefore an installed SVN client 1.8 for the access to the stored Subversion credentials is required. For a correct calculation of the version, the access to the SVN repository must be available.
Caution
|
|
If there is no access to a remote repository, it is possible to specify a version string as project property offlineVersion
(see above)
gradlew -PofflineVersion=9.9.0.0-LOCAL publish
This will add the version '9.9.0.0-LOCAL' to your project. It is possible to add this property also to the gradle.properties file in the Gradle user home. In this case all projects with this applied plugin uses the same version.
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
This command will reset the version to the standard behaviour.
Caution
|
This version will be published to the specified repository and can be used by other processes! |
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. Depending on a special environment configuration (RUNONCI) the build extension is empty or SNAPSHOT, if this setting is true, otherwise it is LOCAL. 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.
-
Trunk
The plugin is looking for a tag that matches the specified criteria. In the most cases, the version is calculated from branches and will be extended withSNAPSHOT
. This behavior can be configured. -
Branch / Feature,Hotfix,Bugfix Branch
The plugin is looking for a tag that matches the branch name. 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.
To use the Gradle SCM Version plugin provided by Intershop, include the following in your build script of your root project:
plugins {
id 'com.intershop.gradle.scmversion' version '4.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')
filterProject = true
}
}
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 project property |
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 tag of the previous version. It is possible to specify another 'previous' version. |
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 |
---|---|---|
prefixes(configure) |
This is the extension object for the configuration of branch prefixes. |
|
user(configure) |
This extension is used for the SCM user authentication. |
|
key(configure) |
This is also used for the SCM user authentication. |
|
version(configure) |
This extension contains settings for version calculation and reads properties for the current version and previous version. |
|
changelog(configure) |
This extension contains settings for change log configuration. |
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 |
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 | Values | Description |
---|---|---|---|---|
type |
|
|
|
The number of used decimal numbers for a version number. |
dryRun |
|
|
|
Tasks will run without changes on the working copy or SCM. |
runOnCI |
|
|
|
This configuration must be |
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 |
version |
|
initialVersion |
read only |
Returns the version of the working copy |
branchName |
|
'' |
read only |
Returns the branch name only (String after last /) |
versionExt |
|
'' |
read only |
see description for |
previousVersion |
|
'' |
read only |
Returns the previous version of the working copy. |
previousVersionTag |
|
|
read only |
Returns an object with the previous version and the associated release tag. |
continuousRelease |
|
|
- |
If this value is true and the publishing runs on a CI server the revision id or the hash string with the prefix "rev.id." will attached to the version instead of SNAPSHOTS. |
continuousReleaseBranches |
|
|
- |
continuousRelease is always used if the active branch is master or trunk. If continuous releases should be done from other branches, it is possible to extend the list of branches with this property. |
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. |
filterProject |
|
|
Filter changed files for projects (first folder in changed files must be identical to last folder of project svn url) |
plugins {
id 'com.intershop.gradle.scmversion' version '4.0.0'
}
scm {
version {
type = 'threeDigits'
initialVersion = '1.0.0'
}
}
version = scm.version.version
This configuration works for Subversion and Git (http(s)://…). It is necessary to specify username and password for this kind of repositories.
scmUserName = username
scmUserPasswd = password
This configuration works for GitLab / GitHub (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 '4.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 -PrunOnCI=true -PscmVersionExt=SNAPSHOT
./gradlew publish -PrunOnCI=true -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 |
---|---|---|
svnurl |
Root URL of the test project |
Must be specified with environment variable |
svnuser |
User name of Subversion test user |
Must be specified with environment variable |
svnpasswd |
Password for Subversion test user |
Must be specified with environment variable |
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 |
Copyright 2014-2016 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.