From 894c7a894c54910824f2a049bdd7d287389b799f Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Thu, 6 Apr 2023 19:17:08 +0400 Subject: [PATCH] get build version on configuration stage (#197) --- build.gradle | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index fa578435..ee8d223b 100644 --- a/build.gradle +++ b/build.gradle @@ -33,6 +33,8 @@ plugins { group = 'io.emeraldpay.dshackle' +version = getVersion() + java { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 @@ -194,7 +196,6 @@ jar { afterEvaluate { distZip.dependsOn(jar) - generateVersion.dependsOn(getVersion) compileKotlin.dependsOn(generateVersion) jar.dependsOn(generateVersion) } @@ -313,17 +314,22 @@ tasks.withType(Detekt).configureEach { jvmTarget = "17" } -task getVersion { +static def getVersion() { def exactVersion = 'git describe --tags --exact-match'.execute().text.trim() + def result = "" if (exactVersion) { - version = exactVersion + result = exactVersion } else { def tag = 'git describe --tags --abbrev=0'.execute().text.trim() + if (!tag) { + throw new GradleException("No tags found") + } def m = tag =~ /\.(\d+)$/ def match = m[0][1] def next = match.toInteger() + 1 tag = tag.replaceAll(/.\d+$/, "." + next.toString()) - version = tag + '-SNAPSHOT' + result = tag + '-SNAPSHOT' } - version = version.replaceAll(/^v/, '') + + return result.replaceAll(/^v/, '') }