Skip to content

Commit 0975eb2

Browse files
committed
print build version before build, pull build version from the last tag in git
1 parent 6e42b9d commit 0975eb2

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

build.gradle.kts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.gradle.internal.extensions.core.extra
2+
13
buildscript {
24
repositories {
35
google()
@@ -18,4 +20,20 @@ tasks {
1820
gradleVersion = libs.versions.gradle.get()
1921
distributionType = Wrapper.DistributionType.BIN
2022
}
23+
}
24+
25+
rootProject.extra.set("gitVersionName", fetchGitVersionName())
26+
rootProject.extra.set("gitVersionCode", fetchGitVersionCode())
27+
28+
fun fetchGitVersionCode(): String = "git rev-list HEAD --count".execute()
29+
30+
fun fetchGitVersionName(): String = "git describe HEAD".execute()
31+
32+
fun String.execute(): String {
33+
val process = ProcessBuilder(*split(" ").toTypedArray())
34+
.redirectOutput(ProcessBuilder.Redirect.PIPE)
35+
.redirectError(ProcessBuilder.Redirect.PIPE)
36+
.start()
37+
process.waitFor()
38+
return process.inputStream.bufferedReader().readText().trim()
2139
}

pdfviewer/build.gradle.kts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ plugins {
77
id("kotlin-parcelize")
88
}
99

10-
version = project.properties["VERSION_NAME"].toString()
10+
val gitVersionName: String by rootProject.extra
11+
version = gitVersionName
1112
group = project.properties["GROUP"].toString()
12-
1313
android {
1414
namespace = "com.pnuema.android.pdfviewer"
1515
base.archivesName.set("compose-pdf-viewer")
@@ -24,13 +24,17 @@ android {
2424
buildTypes {
2525
release {
2626
isMinifyEnabled = false
27+
isShrinkResources = false
2728
proguardFiles(
2829
getDefaultProguardFile("proguard-android-optimize.txt"),
2930
"proguard-rules.pro"
3031
)
32+
enableUnitTestCoverage = false
3133
}
3234
debug {
3335
isMinifyEnabled = false
36+
isShrinkResources = false
37+
enableUnitTestCoverage = true
3438
}
3539
}
3640
compileOptions {
@@ -59,6 +63,12 @@ dependencies {
5963
debugImplementation(libs.androidx.compose.ui.tooling)
6064
}
6165

66+
tasks.register("version") {
67+
doFirst {
68+
println("Version Name: $gitVersionName")
69+
}
70+
}
71+
6272
val dokkaOutputDir = layout.buildDirectory.dir("dokka")
6373
tasks {
6474
val sourcesJar by registering(Jar::class, fun Jar.() {
@@ -99,4 +109,8 @@ tasks {
99109
build {
100110
dependsOn(dokkaGenerate)
101111
}
112+
113+
preBuild {
114+
dependsOn("version")
115+
}
102116
}

0 commit comments

Comments
 (0)