Skip to content

Commit fa757be

Browse files
authored
Feats/modules (#4)
* fix: Add new developer information for Emanuele Iannuzzi in build.gradle.kts * feat: Enhance Maven publishing with automatic release and conditional signing * feat: Introduce Gradle Kotlin DSL configuration and restructure project files * feat: Add LogTide convention plugin and update dependencies for Jakarta, Ktor, and Spring Boot * feat: Implement LogTide middleware for Jakarta Servlet and Spring Boot with request/response logging * feat: Replace println statements with logger.info for improved logging in LogTide components * fix: Add LogTideFilter import to LogTideFilterTest * fix: Add LogTideInterceptor import to LogTideInterceptorTest * feat: Refactor LogTidePluginTest to use installLogtideDefault for cleaner setup * feat: Update build configuration to use projectGroup and projectVersion properties * feat: Remove checkVersionTag task and its dependencies from build configuration * fix: Rename header from X-Trace-ID to Custom-Trace-Header in LogTidePluginTest
2 parents a0e0ebc + df99984 commit fa757be

45 files changed

Lines changed: 413 additions & 244 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ out/
3737
bin/
3838
gen/
3939
target/
40-
/gradle.properties
4140
/secret.gpg
4241
/secring.gpg
4342
/.claude/

build.gradle.kts

Lines changed: 72 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,103 @@
11
import com.vanniktech.maven.publish.MavenPublishBaseExtension
2+
import com.vanniktech.maven.publish.SonatypeHost
3+
import helpers.configureMavenCentralMetadata
4+
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
25
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
36
import kotlin.io.encoding.Base64
47
import 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
}

buildSrc/build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
mavenLocal()
7+
mavenCentral()
8+
maven { url = uri("https://packages.confluent.io/maven/") }
9+
}
10+
11+
dependencies {
12+
gradleApi()
13+
}

buildSrc/src/main/kotlin/Libs.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import org.gradle.api.Project
2+
import org.gradle.api.artifacts.VersionCatalogsExtension
3+
import org.gradle.kotlin.dsl.findByType
4+
5+
@PublishedApi
6+
internal inline val Project.libsVersionCatalog
7+
get() = extensions.findByType<VersionCatalogsExtension>()?.named("libs")
8+
?: error("Version catalog 'libs' not found")
9+
10+
@PublishedApi
11+
internal inline val Project.frameworksVersionCatalog
12+
get() = extensions.findByType<VersionCatalogsExtension>()?.named("frameworks")
13+
?: error("Version catalog 'frameworks' not found")
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package helpers
2+
3+
import org.gradle.api.Project
4+
import org.gradle.api.provider.Property
5+
import org.gradle.api.publish.maven.MavenPom
6+
7+
private infix fun <T> Property<T>.by(value: T) = set(value)
8+
9+
@Suppress("Unused")
10+
fun MavenPom.configureMavenCentralMetadata(project: Project) {
11+
name by project.name
12+
description by "Official Kotlin SDK for LogTide - Self-hosted log management with batching, retry logic, circuit breaker, and query API"
13+
url by "https://github.com/logtide-dev/logtide-sdk-kotlin"
14+
15+
licenses {
16+
license {
17+
name.set("MIT License")
18+
url.set("https://opensource.org/licenses/MIT")
19+
}
20+
}
21+
22+
developers {
23+
developer {
24+
id by "polliog"
25+
name by "Polliog"
26+
email by "giuseppe@solture.it"
27+
}
28+
developer {
29+
id by "emanueleiannuzzi"
30+
name by "Emanuele Iannuzzi"
31+
email by "hello@emanueleiannuzzi.me"
32+
}
33+
}
34+
35+
scm {
36+
connection by "scm:git:git://github.com/logtide-dev/logtide-sdk-kotlin.git"
37+
developerConnection by "scm:git:ssh://github.com/logtide-dev/logtide-sdk-kotlin.git"
38+
url by "https://github.com/logtide-dev/logtide-sdk-kotlin"
39+
}
40+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package plugins
2+
3+
import libsVersionCatalog
4+
import org.gradle.api.Plugin
5+
import org.gradle.api.Project
6+
7+
class LogtideConventionPlugin : Plugin<Project> {
8+
override fun apply(target: Project) {
9+
with(target) {
10+
val libs = libsVersionCatalog
11+
pluginManager.apply(libs.findPlugin("kotlin-jvm").get().get().pluginId)
12+
13+
dependencies.apply {
14+
add("implementation", libs.findBundle("kotlin").get())
15+
add("compileOnly", libs.findBundle("slf4j").get())
16+
17+
add("testImplementation", libs.findBundle("test-slf4j").get())
18+
add("testImplementation", libs.findBundle("test-kotlin").get())
19+
add("testImplementation", libs.findBundle("test-okhttp").get())
20+
}
21+
}
22+
}
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
implementation-class=plugins.LogtideConventionPlugin

gradle.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Gradle Properties
2+
org.gradle.parallel=false
3+
org.gradle.jvmargs=-Dfile.encoding=UTF-8
4+
org.gradle.configuration.cache=true
5+
org.gradle.caching=true
6+
# Project Properties
7+
projectGroup=io.github.logtide-dev
8+
projectVersion=0.5.0
9+
# Kotlin
10+
kotlinJvmTarget=17

gradle/frameworks.versions.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[versions]
2+
spring-boot = "3.2.0"
3+
ktor = "2.3.7"
4+
jakarta = "6.0.0"
5+
6+
[plugins]
7+
8+
[libraries]
9+
spring-boot-starter-web = { module = "org.springframework.boot:spring-boot-starter-web", version.ref = "spring-boot" }
10+
ktor-server-core = { module = "io.ktor:ktor-server-core", version.ref = "ktor" }
11+
jakarta-servlet-api = { module = "jakarta.servlet:jakarta.servlet-api", version.ref = "jakarta" }
12+
13+
# Test
14+
ktor-server-test-host = { module = "io.ktor:ktor-server-test-host", version.ref = "ktor" }
15+
ktor-server-content-negotiation = { module = "io.ktor:ktor-server-content-negotiation", version.ref = "ktor" }
16+
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
17+
18+
spring-test = { module = "org.springframework:spring-test", version = "6.1.1" }
19+
spring-webmvc = { module = "org.springframework:spring-webmvc", version = "6.1.1" }
20+
spring-boot-test = { module = "org.springframework.boot:spring-boot-test", version.ref = "spring-boot" }
21+
22+
[bundles]
23+
test-ktor = ["ktor-server-test-host", "ktor-server-content-negotiation", "ktor-serialization-kotlinx-json"]
24+
test-spring = ["spring-test", "spring-webmvc", "spring-boot-test"]
25+
test-jakarta = ["jakarta-servlet-api"]

0 commit comments

Comments
 (0)