Skip to content

Commit 2447693

Browse files
authored
Update build.gradle
1 parent 4308c9c commit 2447693

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

build.gradle

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'idea'
22
apply plugin: 'eclipse'
33

44
group = 'co.permify'
5-
version = '0.0.1'
5+
version = '0.0.1-SNAPSHOT' // Default version
66

77
buildscript {
88
repositories {
@@ -18,7 +18,25 @@ repositories {
1818
mavenCentral()
1919
}
2020

21-
if(hasProperty('target') && target == 'android') {
21+
// Task to get the current Git commit hash
22+
task getCommitHash {
23+
doLast {
24+
def commitHash = 'git rev-parse --short HEAD'.execute().text.trim()
25+
project.ext.commitHash = commitHash
26+
}
27+
}
28+
29+
// Update the version with the commit hash
30+
task updateVersion {
31+
dependsOn getCommitHash
32+
doLast {
33+
def commitHash = project.ext.commitHash
34+
version = "${version}-${commitHash}"
35+
println "Updated version to: $version"
36+
}
37+
}
38+
39+
if (hasProperty('target') && target == 'android') {
2240

2341
apply plugin: 'com.android.library'
2442
apply plugin: 'com.github.dcendents.android-maven'
@@ -36,7 +54,6 @@ if(hasProperty('target') && target == 'android') {
3654
targetCompatibility JavaVersion.VERSION_1_8
3755
}
3856

39-
// Rename the aar correctly
4057
libraryVariants.all { variant ->
4158
variant.outputs.each { output ->
4259
def outputFile = output.outputFile
@@ -54,7 +71,7 @@ if(hasProperty('target') && target == 'android') {
5471

5572
afterEvaluate {
5673
android.libraryVariants.all { variant ->
57-
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
74+
def task = project.tasks.create("jar${variant.name.capitalize()}", Jar)
5875
task.description = "Create jar artifact for ${variant.name}"
5976
task.dependsOn variant.javaCompile
6077
task.from variant.javaCompile.destinationDirectory
@@ -96,11 +113,13 @@ if(hasProperty('target') && target == 'android') {
96113
maven(MavenPublication) {
97114
artifactId = 'permify'
98115
from components.java
116+
// Include the commit hash in the published version
117+
version = "${version}"
99118
}
100119
}
101120
}
102121

103-
task execute(type:JavaExec) {
122+
task execute(type: JavaExec) {
104123
mainClass = System.getProperty('mainClass')
105124
classpath = sourceSets.main.runtimeClasspath
106125
}

0 commit comments

Comments
 (0)