Skip to content

Commit 283f30c

Browse files
authored
Feature: Add JPMS Support (Issue #365) (#592)
## Description This PR adds support for the Java Platform Module System (JPMS) by introducing a `module-info.java` file. This allows `kotlin-logging` to be used as a named module in modularized Java applications. Resolves #365. ## Technical Details - Added `src/jvmMain/java/module-info.java` defining the `io.github.oshai.kotlinlogging` module. - Leveraged standard Kotlin Multiplatform (KMP) support for Java source sets (valid in Kotlin 2.1+). - Updated `build.gradle.kts` to: - Configure `compileJvmMainJava` with `--patch-module` to allow `module-info.java` to see Kotlin classes in the same module. - Preserved `jvmTarget = 1.8` for Kotlin classes to maintain Android and Java 8 compatibility. - Configured `gradle.properties` to allow mixed JVM targets (1.8 for Kotlin, 9+ for `module-info`). - Added static requirements for optional dependencies: - `ch.qos.logback.classic` & `core` - `kotlinx.coroutines.slf4j` - `org.graalvm.nativeimage` ## Verification - Verified that `./gradlew jvmJar` builds successfully. - Verified `module-info.class` is matching JDK 9+ (implicitly). - Verified Kotlin classes target Java 1.8 (major version 52). Fixes #365
1 parent e5366c2 commit 283f30c

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,5 @@ hs_err_pid*
7676
github_packages.properties
7777
github_packages.properties.old
7878
/kotlin-js-store/yarn.lock
79+
80+
.vscode

build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ kotlin {
4545
jvm {
4646
compilations {
4747
val main by getting
48+
tasks.named<JavaCompile>("compileJvmMainJava") {
49+
options.compilerArgs.add("--patch-module")
50+
options.compilerArgs.add("io.github.oshai.kotlinlogging=${main.output.classesDirs.asPath}")
51+
}
4852
// logback tests are testing only direct logback dependency (not slf4j/log4j)
4953
val logbackTest by compilations.creating {
5054
defaultSourceSet {

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ org.gradle.jvmargs=-Xmx2048m
44
# see https://kotlinlang.org/docs/whatsnew18.html#sourcedirectories
55
kotlin.mpp.androidSourceSetLayoutVersion=2
66
kotlin.mpp.applyDefaultHierarchyTemplate=false
7+
# Allow inconsistent JVM targets: Kotlin targets 1.8 (for compatibility), but module-info.java requires 9+.
8+
kotlin.jvm.target.validation.mode=warning

src/jvmMain/java/module-info.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module io.github.oshai.kotlinlogging {
2+
requires kotlin.stdlib;
3+
requires kotlinx.coroutines.core;
4+
requires org.slf4j;
5+
requires java.logging;
6+
requires static ch.qos.logback.classic;
7+
requires static ch.qos.logback.core;
8+
requires static kotlinx.coroutines.slf4j;
9+
requires static org.graalvm.nativeimage;
10+
11+
exports io.github.oshai.kotlinlogging;
12+
exports io.github.oshai.kotlinlogging.coroutines;
13+
exports io.github.oshai.kotlinlogging.logback;
14+
exports io.github.oshai.kotlinlogging.slf4j;
15+
}

0 commit comments

Comments
 (0)