hfhbd
05/13/2025, 9:48 PMjvm().withJava()
is deprecated in KMP to support Gradle 9. But KMP does also not allow multiple jvm targets. How exactly do I create a multi release jar (for JPMS support)? Currently, I use jvm().withJava()
to create a jvm9 java sourceSet (bypassing the multiple jvm targets).hfhbd
05/13/2025, 9:48 PMplugins {
id("kotlinMPPSetup")
}
kotlin {
jvm {
withJava()
}
}
val java9 by java.sourceSets.registering
tasks.jvmJar {
into("META-INF/versions/9") {
from(java9.map { it.output })
}
manifest.attributes("Multi-Release" to true)
}
tasks.named<JavaCompile>("compileJava9Java") {
javaCompiler.set(javaToolchains.compilerFor {})
options.release.set(9)
options.compilerArgumentProviders += object : CommandLineArgumentProvider {
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
val kotlinClasses = tasks.compileKotlinJvm.flatMap { it.destinationDirectory }
override fun asArguments(): List<String> = listOf(
"--patch-module",
"app.softwork.serviceloader.runtime=${kotlinClasses.get().asFile.absolutePath}"
)
}
}
mbonnin
05/13/2025, 9:49 PMmbonnin
05/13/2025, 9:51 PMephemient
05/14/2025, 2:45 AMkotlin {
jvm {
val main by compilations.getting
val main9 by compilations.creating {
compileTaskProvider.configure {
compilerOptions.jvmTarget = JvmTarget.JVM_9
}
compileJavaTaskProvider?.configure {
options.release = 9
}
}
tasks.named<ProcessResources>(main.processResourcesTaskName) {
into("META-INF/versions/9") {
from(main9.output.allOutputs)
exclude("META-INF")
}
}
}
}
but doesn't give you the ability to reference jvmMain
classes from within jvmMain9
, and I'm not sure if there's a decent way to do so without introducing a task dependency cycleephemient
05/14/2025, 2:47 AMval main9 by compilations.creating {
associateWith(main)
and similar tricks with sourceSet.dependsOn
fail)