diff --git a/kotlinx-coroutines-core/build.gradle.kts b/kotlinx-coroutines-core/build.gradle.kts index 4acdf18572..8a72bb2efb 100644 --- a/kotlinx-coroutines-core/build.gradle.kts +++ b/kotlinx-coroutines-core/build.gradle.kts @@ -160,17 +160,24 @@ val jvmJar by tasks.getting(Jar::class) { setupManifest(this) } * This manifest contains reference to AgentPremain that belongs to * kotlinx-coroutines-core-jvm, but our resolving machinery guarantees that * any JVM project that depends on -core artifact also depends on -core-jvm one. + * + * To avoid a conflict with a JPMS module provided by kotlinx-coroutines-core-jvm, + * an explicit automatic module name has to be specified in the manifest. */ -val allMetadataJar by tasks.getting(Jar::class) { setupManifest(this) } +val allMetadataJar by tasks.getting(Jar::class) { + setupManifest(this, "kotlinx.coroutines.core.artifact_disambiguating_module") +} -fun setupManifest(jar: Jar) { +fun setupManifest(jar: Jar, autoModuleName: String? = null) { jar.manifest { attributes( - mapOf( + "Premain-Class" to "kotlinx.coroutines.debug.internal.AgentPremain", - "Can-Retransform-Classes" to "true", - ) + "Can-Retransform-Classes" to "true" ) + autoModuleName?.let { + attributes("Automatic-Module-Name" to it) + } } } diff --git a/kotlinx-coroutines-test/build.gradle.kts b/kotlinx-coroutines-test/build.gradle.kts index 5e29e6ae75..db519b121f 100644 --- a/kotlinx-coroutines-test/build.gradle.kts +++ b/kotlinx-coroutines-test/build.gradle.kts @@ -21,3 +21,9 @@ kotlin { } } } + +val allMetadataJar by tasks.getting(Jar::class) { + manifest { + attributes("Automatic-Module-Name" to "kotlinx.coroutines.test.artifact_disambiguating_module") + } +}