get build version on configuration stage (#197)

This commit is contained in:
a10zn8
2023-04-06 19:17:08 +04:00
committed by GitHub
parent ae9ef97bef
commit 894c7a894c

View File

@@ -33,6 +33,8 @@ plugins {
group = 'io.emeraldpay.dshackle' group = 'io.emeraldpay.dshackle'
version = getVersion()
java { java {
sourceCompatibility = JavaVersion.VERSION_17 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17
@@ -194,7 +196,6 @@ jar {
afterEvaluate { afterEvaluate {
distZip.dependsOn(jar) distZip.dependsOn(jar)
generateVersion.dependsOn(getVersion)
compileKotlin.dependsOn(generateVersion) compileKotlin.dependsOn(generateVersion)
jar.dependsOn(generateVersion) jar.dependsOn(generateVersion)
} }
@@ -313,17 +314,22 @@ tasks.withType(Detekt).configureEach {
jvmTarget = "17" jvmTarget = "17"
} }
task getVersion { static def getVersion() {
def exactVersion = 'git describe --tags --exact-match'.execute().text.trim() def exactVersion = 'git describe --tags --exact-match'.execute().text.trim()
def result = ""
if (exactVersion) { if (exactVersion) {
version = exactVersion result = exactVersion
} else { } else {
def tag = 'git describe --tags --abbrev=0'.execute().text.trim() def tag = 'git describe --tags --abbrev=0'.execute().text.trim()
if (!tag) {
throw new GradleException("No tags found")
}
def m = tag =~ /\.(\d+)$/ def m = tag =~ /\.(\d+)$/
def match = m[0][1] def match = m[0][1]
def next = match.toInteger() + 1 def next = match.toInteger() + 1
tag = tag.replaceAll(/.\d+$/, "." + next.toString()) tag = tag.replaceAll(/.\d+$/, "." + next.toString())
version = tag + '-SNAPSHOT' result = tag + '-SNAPSHOT'
} }
version = version.replaceAll(/^v/, '')
return result.replaceAll(/^v/, '')
} }