11import com.vanniktech.maven.publish.MavenPublishBaseExtension
2+ import com.vanniktech.maven.publish.SonatypeHost
3+ import helpers.configureMavenCentralMetadata
4+ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
25import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
36import kotlin.io.encoding.Base64
47import kotlin.io.encoding.ExperimentalEncodingApi
58
6- plugins {
7- kotlin(" jvm" ) version " 1.9.21"
8- kotlin(" plugin.serialization" ) version " 1.9.21"
9- id(" org.jetbrains.dokka" ) version " 1.9.10"
10- id(" com.vanniktech.maven.publish" ) version " 0.29.0"
11- }
12-
13- group = " io.github.logtide-dev"
14- version = " 0.4.0"
15-
16- repositories {
17- mavenCentral()
18- }
19-
20- dependencies {
21- // Kotlin
22- implementation(kotlin(" stdlib" ))
23-
24- // HTTP Client
25- implementation(" com.squareup.okhttp3:okhttp:4.12.0" )
26- implementation(" com.squareup.okhttp3:okhttp-sse:4.12.0" )
27-
28- // JSON Serialization
29- implementation(" org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0" )
30-
31- // Coroutines
32- implementation(" org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3" )
33-
34- // Logging
35- compileOnly(" org.slf4j:slf4j-api:2.0.9" )
36-
37- // Framework integrations
38- compileOnly(" org.springframework.boot:spring-boot-starter-web:3.2.0" )
39- compileOnly(" io.ktor:ktor-server-core:2.3.7" )
40- compileOnly(" jakarta.servlet:jakarta.servlet-api:6.0.0" )
41-
42- // Testing
43- testImplementation(kotlin(" test" ))
44- testImplementation(" org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3" )
45- testImplementation(" com.squareup.okhttp3:mockwebserver:4.12.0" )
46- testImplementation(" io.mockk:mockk:1.13.8" )
9+ val kotlinJvmTarget: String by project
10+ val projectGroup: String by project
11+ val projectVersion: String by project
4712
48- // Logging for tests (required since slf4j-api is compileOnly)
49- testImplementation(" org.slf4j:slf4j-api:2.0.9" )
50- testImplementation(" org.slf4j:slf4j-simple:2.0.9" )
51-
52- // Framework testing dependencies
53- testImplementation(" io.ktor:ktor-server-test-host:2.3.7" )
54- testImplementation(" io.ktor:ktor-server-content-negotiation:2.3.7" )
55- testImplementation(" io.ktor:ktor-serialization-kotlinx-json:2.3.7" )
56- testImplementation(" org.springframework:spring-test:6.1.1" )
57- testImplementation(" org.springframework:spring-webmvc:6.1.1" )
58- testImplementation(" org.springframework.boot:spring-boot-test:3.2.0" )
59- testImplementation(" jakarta.servlet:jakarta.servlet-api:6.0.0" )
13+ plugins {
14+ alias(libs.plugins.kotlin.jvm) apply false
15+ alias(libs.plugins.maven.publish) apply false
6016}
6117
62- tasks.withType<KotlinCompile > {
63- kotlinOptions {
64- freeCompilerArgs = listOf (" -Xjsr305=strict" )
65- jvmTarget = " 17"
18+ subprojects {
19+ if (projectGroup.isBlank() || projectVersion.isBlank()) {
20+ throw GradleException (" Project group and version must be defined in gradle.properties" )
6621 }
67- }
6822
69- tasks.test {
70- useJUnitPlatform()
71- }
72-
73- java {
74- sourceCompatibility = JavaVersion .VERSION_17
75- targetCompatibility = JavaVersion .VERSION_17
76- }
77-
78- mavenPublishing {
79- publishToMavenCentral(com.vanniktech.maven.publish.SonatypeHost .CENTRAL_PORTAL , automaticRelease = true )
80- signIfKeyPresent(project)
81-
82- coordinates(" io.github.logtide-dev" , " logtide-sdk-kotlin" , version.toString())
83-
84- pom {
85- name.set(" LogTide Kotlin SDK" )
86- description.set(" Official Kotlin SDK for LogTide - Self-hosted log management with batching, retry logic, circuit breaker, and query API" )
87- url.set(" https://github.com/logtide-dev/logtide-sdk-kotlin" )
88-
89- licenses {
90- license {
91- name.set(" MIT License" )
92- url.set(" https://opensource.org/licenses/MIT" )
23+ group = projectGroup
24+ version = projectVersion
25+
26+ apply (plugin = " org.jetbrains.kotlin.jvm" )
27+ apply (plugin = " com.vanniktech.maven.publish" )
28+ apply (plugin = " signing" )
29+
30+ pluginManager.withPlugin(" com.vanniktech.maven.publish" ) {
31+ pluginManager.withPlugin(" signing" ) {
32+ extensions.configure<MavenPublishBaseExtension > {
33+ publishToMavenCentral(
34+ SonatypeHost .CENTRAL_PORTAL ,
35+ automaticRelease = true
36+ )
37+ signIfKeyPresent(this @subprojects)
38+
39+ pom {
40+ configureMavenCentralMetadata(this @subprojects)
41+ }
9342 }
9443 }
44+ }
9545
96- developers {
97- developer {
98- id.set(" polliog" )
99- name.set(" Polliog" )
100- email.set(" giuseppe@solture.it" )
101- }
102- developer {
103- id.set(" emanueleiannuzzi" )
104- name.set(" Emanuele Iannuzzi" )
105- email.set(" hello@emanueleiannuzzi.me" )
46+ plugins.withType<JavaPlugin >().configureEach {
47+ extensions.configure<JavaPluginExtension > {
48+ toolchain {
49+ languageVersion.set(JavaLanguageVersion .of(kotlinJvmTarget))
50+ vendor.set(JvmVendorSpec .AMAZON )
51+ sourceCompatibility = JavaVersion .VERSION_17
52+ targetCompatibility = JavaVersion .VERSION_17
10653 }
10754 }
55+ }
10856
109- scm {
110- connection.set(" scm:git:git://github.com/logtide-dev/logtide-sdk-kotlin.git" )
111- developerConnection.set(" scm:git:ssh://github.com/logtide-dev/logtide-sdk-kotlin.git" )
112- url.set(" https://github.com/logtide-dev/logtide-sdk-kotlin" )
57+ plugins.withId(" org.jetbrains.kotlin.jvm" ) {
58+ extensions.configure<KotlinJvmProjectExtension > {
59+ jvmToolchain(kotlinJvmTarget.toInt())
11360 }
11461 }
115- }
11662
117- tasks.register(" printVersion" ) {
118- doLast {
119- println (project.version.toString())
63+ tasks.withType<KotlinCompile > {
64+ kotlinOptions {
65+ freeCompilerArgs = listOf (" -Xjsr305=strict" )
66+ jvmTarget = kotlinJvmTarget
67+ }
12068 }
121- }
122-
123- tasks.register(" checkVersionTag" ) {
124- doLast {
125- val tag = System .getenv(" GITHUB_REF_NAME" )
126- ?.removePrefix(" v" )
127- ? : return @doLast
128-
129- val versionString = project.version.toString()
13069
131- if (versionString != tag) {
132- throw GradleException (
133- " Version mismatch: project.version=$versionString , tag=$tag "
134- )
135- }
70+ tasks.withType<Test > {
71+ useJUnitPlatform()
13672 }
13773}
13874
139- tasks[" publishAndReleaseToMavenCentral" ].dependsOn(" checkVersionTag" )
140-
14175@OptIn(ExperimentalEncodingApi ::class )
142- fun MavenPublishBaseExtension.signIfKeyPresent (project : Project ) {
143- val keyId = System .getenv(" KEY_ID" ).also {
144- if (it == null ) {
145- println (" KEY_ID environment variable not set, assuming binary .gpg key." )
146- }
147- }
148- val keyBytes = System .getenv(" SECRING" )?.let { Base64 .decode(it.toByteArray()).decodeToString() }
76+ private fun MavenPublishBaseExtension.signIfKeyPresent (project : Project ) {
77+ val keyId = System .getenv(" KEY_ID" )
78+ val keyBytes = runCatching {
79+ Base64 .decode(System .getenv(" SECRING" ).toByteArray()).decodeToString()
80+ }.getOrNull()
14981 val keyPassword = System .getenv(" PASSWORD" )
15082
151- if (keyBytes == null || keyPassword == null ) {
152- println (" Signing environment variables not set, skipping signing." )
153- return
83+ if (keyBytes != null && keyPassword != null ) {
84+ println (" Signing artifacts with in-memory PGP key (.gpg)" )
85+ project.extensions.configure<SigningExtension >(" signing" ) {
86+ // For binary .gpg keys
87+ if (keyId == null ) {
88+ useInMemoryPgpKeys(keyBytes, keyPassword)
89+ } else {
90+ useInMemoryPgpKeys(keyId, keyBytes, keyPassword)
91+ }
92+ signAllPublications()
93+ }
94+ } else {
95+ println (" Skipping signing of artifacts: PGP key or password not found in environment variables" )
15496 }
97+ }
15598
156- project.extensions.configure<SigningExtension >(" signing" ) {
157- // For binary .gpg keys
158- if (keyId == null ) {
159- useInMemoryPgpKeys(keyBytes, keyPassword)
160- } else {
161- useInMemoryPgpKeys(keyId, keyBytes, keyPassword)
162- }
163- signAllPublications()
99+ tasks.register(" printVersion" ) {
100+ doLast {
101+ println (project.version.toString())
164102 }
165103}
0 commit comments