Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

otto-de/gradle-projectversion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gradle-projectversion

Automatic versioning of your gradle-built artifacts.

Usage

The minimum required Gradle version is 5.1 as the plugin uses lazy properties.

The plugin must be activated with the following steps:

  1. Ensure that the current version x.y.z of your project is reflected as a tag with the pattern vx.y.z in your Git repository.
  2. Remove any preconfigured project.version assignment in your build.gradle.
  3. Apply the plugin with your method of choice.
  4. Configure the versioning strategy employed by the plugin.

The second step is necessary for the plugin to do anything useful. Refer to the next section for example configurations.

During execution, the version property is automatically derived from the latest Git tag using the configured strategy. This is done on first access of the property. Therefore, the configuration should be near the top of your build.gradle. The plugin provides the buildInfo task which may be used to print the computed version.

Depending on the state of your Git repository, the following will happen:

  • Current commit is tagged and workspace is clean → Current Version from Git tag is used.
  • Current commit is not tagged and workspace is clean → Next version based on latest tagged commit is used.
  • Workspace is dirty → Next version suffixed with -SNAPSHOT is used.

The plugin provides the tagVersion task to store the computed version as Git tag.

Examples

Print build info

plugins {
    id 'de.otto.find.project-version' version '0.8.0'
}
$ ./gradlew buildInfo

> Task :buildInfo
gradleVersion=5.6.2
name=gradle-projectversion
group=de.otto.find
version=0.8.0
commit=aaccf75161bf4dc1cc5337622cba24e43525d9ac

Auto-versioning in Git repositories

plugins {
    id 'de.otto.find.project-version' version '0.8.0'
}

projectVersion {
    useSemanticVersioning() {
        majorVersion = 1
    }
}

Sprint-based major versions

plugins {
    id 'de.otto.find.project-version' version '0.8.0'
}

projectVersion {
    useSemanticVersioning() {
        useSprintNumber() {
            sprintStart = Instant.parse("2011-09-28T23:00:00Z")
            sprintLength = Duration.ofDays(14)
            sprintStartNumber = 1
        }
    }
}

Extending build info

plugins {
    id 'de.otto.find.project-version' version '0.8.0'
}

projectVersion {
    buildInfo([
            team    : 'teamname',
            vertical: 'projectvertical'
    ])
}

Using build info to filter resources

import org.apache.tools.ant.filters.ReplaceTokens

plugins {
    // Apply the java plugin to add support for Java
    id 'java'

    // Auto-versioning
    id 'de.otto.find.project-version' version '0.8.0'
}

tasks.withType(ProcessResources) {
    doFirst {
        logger.quiet "Build Info: [$name]"
        logger.quiet "--------------------------------------------------------------"
        inputs.properties.buildInfo.each { k, v -> logger.quiet "${k} : ${v}" }
        logger.quiet "--------------------------------------------------------------"
    }

    inputs.property 'buildInfo', projectVersion.buildInfo

    filter ReplaceTokens, tokens: inputs.properties.buildInfo
}

Setting a fixed version

plugins {
    id 'de.otto.find.project-version' version '0.8.0'
}

projectVersion {
    version = '1.2.0'
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages