File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import org.gradle.internal.extensions.core.extra
2+
13buildscript {
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}
Original file line number Diff line number Diff 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
1112group = project.properties[" GROUP" ].toString()
12-
1313android {
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+
6272val dokkaOutputDir = layout.buildDirectory.dir(" dokka" )
6373tasks {
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}
You can’t perform that action at this time.
0 commit comments