@@ -8,9 +8,35 @@ plugins {
8
8
`maven- publish`
9
9
}
10
10
11
- val artifact = System .getenv(" artifact" ) ? : " sdk"
12
- group = System .getenv(" group" ) ? : " net.tcgdex"
13
- version = System .getenv(" version" ) ? : " 2.0.0"
11
+ // from: https://discuss.kotlinlang.org/t/use-git-hash-as-version-number-in-build-gradle-kts/19818/8
12
+ fun String.runCommand (
13
+ workingDir : File = File ("."),
14
+ timeoutAmount : Long = 60,
15
+ timeoutUnit : TimeUnit = TimeUnit .SECONDS
16
+ ): String = ProcessBuilder (split(" \\ s(?=(?:[^'\" `]*(['\" `])[^'\" `]*\\ 1)*[^'\" `]*$)" .toRegex()))
17
+ .directory(workingDir)
18
+ .redirectOutput(ProcessBuilder .Redirect .PIPE )
19
+ .redirectError(ProcessBuilder .Redirect .PIPE )
20
+ .start()
21
+ .apply { waitFor(timeoutAmount, timeoutUnit) }
22
+ .run {
23
+ val error = errorStream.bufferedReader().readText().trim()
24
+ if (error.isNotEmpty()) {
25
+ return @run " "
26
+ }
27
+ inputStream.bufferedReader().readText().trim()
28
+ }
29
+
30
+ val branch = " git rev-parse --abbrev-ref HEAD" .runCommand(workingDir = rootDir)
31
+ val tag = " git tag -l --points-at HEAD" .runCommand(workingDir = rootDir)
32
+ val commitId = " git rev-parse HEAD" .runCommand(workingDir = rootDir)
33
+
34
+ val finalVersion = System .getenv(" version" ) as String? ? : tag.drop(1 ) ? : " 2.0.0"
35
+ val finalGroup = System .getenv(" group" ) as String? ? : " net.tcgdex"
36
+ val artifact = System .getenv(" artifact" ) as String? ? : " sdk"
37
+
38
+ group = finalGroup
39
+ version = finalVersion
14
40
15
41
repositories {
16
42
mavenCentral()
@@ -56,39 +82,9 @@ val javadocJar = tasks.named<Jar>("javadocJar") {
56
82
publishing {
57
83
publications {
58
84
create<MavenPublication >(" maven" ) {
59
- // groupId = group
60
- artifactId = artifact
61
- // version = ver
62
-
63
- from(components[" java" ])
64
-
65
- pom {
66
- name.set(" TCGdex SDK" )
67
- description.set(" Communicate with the Open Source TCGdex API in Kotlin/Java using the SDK" )
68
- url.set(" https://github.com/tcgdex/java-sdk" )
69
- licenses {
70
- license {
71
- name.set(" MIT License" )
72
- url.set(" https://github.com/tcgdex/java-sdk/blob/master/LICENSE.txt" )
73
- }
74
- }
75
- developers {
76
- developer {
77
- id.set(" avior" )
78
- name.set(" Avior" )
79
-
80
- }
81
- }
82
- scm {
83
- connection.set(
" scm:[email protected] :tcgdex/java-sdk.git" )
84
- url.set(" https://github.com/tcgdex/java-sdk" )
85
- }
86
- }
87
- }
88
- register<MavenPublication >(" gpr" ) {
89
- // groupId = group
85
+ groupId = finalGroup
90
86
artifactId = artifact
91
- // version = ver
87
+ version = finalVersion
92
88
93
89
from(components[" java" ])
94
90
0 commit comments