Gradle plugin for populating project.version
property based on semantic version specification.
The vcs-semantic-version plugin is hosted at Gradle Plugins Portal, Bintray's JCenter and Maven Central.
The following functionality is provided by the vcs-semantic-version plugin:
- Auto detects version control system of project
- Populates
project.version
property with such patternMAJOR.MINOR.PATCH-PRE_RELEASE
Gradle >= 2.1
plugins {
id 'com.github.moleksyuk.vcs-semantic-version' version '1.1.3'
}
Gradle < 2.1
apply plugin: 'com.github.moleksyuk.vcs-semantic-version'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.moleksyuk:vcs-semantic-version:1.1.3'
}
}
Configure the plugin through the semanticVersion
extension.
semanticVersion {
major = 1 // required
minor = 0 // required
preRelease = 'beta' // optional
accurev.stream = 'MyStream' // required only for ACCUREV VCS
}
Specify task that should depends on buildSemanticVersion
task.
For example:
jar.dependsOn buildSemanticVersion
There are some tasks in plugins that use project.version
.
For example:
- plugin:
java
task:jar
- builds artifact with specified version - plugin:
sonar-runner
task:sonarRunner
- publishes code quality results into SonarQube - plugin:
maven
task:uploadArchives
- publishes artifact to Maven repository - plugin:
maven-publish
task:publish
- publishes artifact to Maven repository
Having multiple plugins that depend on project.version
property requires to define dependency for each task:
jar.dependsOn buildSemanticVersion
tasks.sonarRunner.dependsOn buildSemanticVersion
....
More over maven-publish
plugin has issue with dynamically populated project.version
property.
To fix all these troubles use such configuration.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.moleksyuk:vcs-semantic-version:1.1.3'
}
}
import com.github.moleksyuk.plugin.SemanticVersionPluginExtension
project.extensions.create(SemanticVersionPluginExtension.NAME, SemanticVersionPluginExtension)
semanticVersion {
major = 1
minor = 2
}
apply plugin: 'com.github.moleksyuk.vcs-semantic-version'
The complete example:
import com.github.moleksyuk.plugin.SemanticVersionPluginExtension
project.extensions.create(SemanticVersionPluginExtension.NAME, SemanticVersionPluginExtension)
semanticVersion {
major = 1
minor = 2
}
apply plugin: 'com.github.moleksyuk.vcs-semantic-version'
apply plugin: 'maven-publish' // must be after vcs-semantic-version
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.moleksyuk:vcs-semantic-version:1.1.3'
}
}
NOTE: Keep in mind that all dependent plugins on project.version
should be applied after row:
apply plugin: 'com.github.moleksyuk.vcs-semantic-version'
- If root project folder contains
.git
folder thenGIT
version control system is used - If root project folder contains
.hg
folder thenMERCURIAL
version control system is used - If root project folder contains
.svn
folder thenSUBVERSION
version control system is used - If non of above but contains
.acignore
file thenACCUREV
version control system is used
For GIT
git rev-list HEAD --count
For MERCURIAL
hg id --num --rev tip
For SUBVERSION
svnversion .
For ACCUREV
accurev hist -ft -t highest -s [accurev.stream]
MAJOR.MINOR.PATCH-PRE_RELEASE
where:
MAJOR
- specified insemanticVersion
extensionMINOR
- specified insemanticVersion
extensionPATCH
- calculated in step#2PRE_RELEASE
- specified insemanticVersion
extension