Skip to content

Commit 885c4be

Browse files
committed
task: add publish configuration to Gradle
1 parent 91f4424 commit 885c4be

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

build.gradle.kts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
kotlin("jvm") version "2.0.21"
33
kotlin("plugin.serialization") version "2.1.0"
4+
`maven-publish`
45
}
56

67
group = "org.ctrlhub"
@@ -23,6 +24,42 @@ dependencies {
2324
testImplementation(libs.ktor.client.mock)
2425
}
2526

27+
fun Project.getGitTag(): String {
28+
return try {
29+
val process = ProcessBuilder("git", "describe", "--tags", "--abbrev=0")
30+
.redirectErrorStream(true)
31+
.start()
32+
process.waitFor(10, TimeUnit.SECONDS)
33+
process.inputStream.bufferedReader().readText().trim()
34+
} catch (e: Exception) {
35+
"0.0.0" // Default version if no tags are found
36+
}
37+
}
38+
39+
publishing {
40+
repositories {
41+
maven {
42+
name = "GitHubPackages"
43+
url = uri("https://maven.pkg.github.com/ctrl-hub/sdk.kotlin")
44+
45+
credentials {
46+
username = System.getenv("GITHUB_USERNAME")
47+
password = System.getenv("GITHUB_TOKEN")
48+
}
49+
}
50+
}
51+
52+
publications {
53+
create<MavenPublication>("gpr") {
54+
groupId = "com.ctrlhub"
55+
artifactId = "sdk"
56+
version = project.getGitTag()
57+
58+
from(components["kotlin"])
59+
}
60+
}
61+
}
62+
2663
tasks.test {
2764
useJUnitPlatform()
2865
}

0 commit comments

Comments
 (0)