summaryrefslogtreecommitdiff
path: root/gradle/scripts/git-scm-version.gradle
blob: c6a7cfa094f99a8f97cc6b136d42d2f86dbc15d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//THX to https://proandroiddev.com/configuring-android-project-version-name-code-b168952f3323

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.ajoberstar:grgit:2.3.0'
    }
}

import org.ajoberstar.grgit.Grgit
import java.time.format.DateTimeFormatter

ext {
    git = Grgit.open(currentDir: projectDir)
    gitVersionName = git.describe(match: ["v[0-9.rc]*"])
    hh = Integer.parseInt(DateTimeFormatter.ofPattern("HH").format(git.head().dateTime))
    mm = Integer.parseInt(DateTimeFormatter.ofPattern("mm").format(git.head().dateTime))
    hhmm = Math.round((hh*4)+(mm/15)).toString()
    yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd").format(git.head().dateTime)
    gitVersionCode = Integer.parseInt(yyyyMMdd + hhmm)
}

task printVersion() {
    println("Version Name: $gitVersionName")
    println("Version Code: $gitVersionCode")
}