Skip to content

Advanced Usage

Hieu Rocker edited this page Apr 19, 2018 · 5 revisions

Custom git repo

By default the plugin will try to find the git repo in the root project directory. But you can change it to any git repo that you want by setting gitDir:

versionberg {
    major 1
    minor 0
    gitDir new File("path/to/git/repo/.git")
}

Template variables

You can use your own version code, version name format with Versionberg. Available variables are:

  • major: increase this version when you make incompatible API changes
  • minor: increase this version when you add functionality in a backwards-compatible manner
  • patch: increase this version when you make backwards-compatible bug fixes
  • build: an increasement integer to identify the build. Versionberg uses commit count of the current branch for this variable
  • commitCount: commit count of the current branch
  • commitSha: SHA of the latest commit
  • today: today in yyyyMMdd format, e.g 20180131 (will be released in v1.0.2)

Example

versionberg {
    // Increase when you make incompatible API changes (default value is 0)
    major 1

    // Increase when you add functionality in a backwards-compatible manner (default value is 0)
    minor 0

    // Increase when you make backwards-compatible bug fixes (default value is 0)
    patch 0

    // default is ${commitCount}, uncomment to use a custom build number
    // build 2

    // Default version name template is '${major}.${minor}.${patch}.${build}'
    nameTemplate '${major}.${minor}.${new Date().format("ddMMyyyy")}-SNAPSHOT'
    
    // Default version code template is '${build}'
    codeTemplate '(((${major} * 100) + ${minor}) * 100) * 100000 + ${build}'
}

You can put date into the template, i.e ${new Date().format("ddMMyyyy")}, see more at SimpleDateFormat.

My config

This is the config that I been using for some years:

versionberg {
    major 1
    minor 0
    nameTemplate '${major}.${minor}.${commitCount}.${commitSha}'
    codeTemplate '(((${major} * 100) + ${minor}) * 100) * 100000 + ${build}'
}

Main advantages:

  • ${commitCount}: easy to reference to a version when communicating
  • ${commitSha}: easy to identify the git revision of a given build
Clone this wiki locally