From f7396c59b3469866e4d93a45cbc8dba13a7ab873 Mon Sep 17 00:00:00 2001 From: Filipp Zhinkin Date: Fri, 3 Jan 2025 16:58:49 -0500 Subject: [PATCH 1/2] Specify Automatic-Module-Name for kotlinx-coroutines-core Fixes #3842 --- README.md | 2 +- kotlinx-coroutines-core/build.gradle.kts | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d39cf315e1..2ad89d1403 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ Add dependencies (you can also add other modules that you need): ```xml org.jetbrains.kotlinx - kotlinx-coroutines-core + kotlinx-coroutines-core-jvm 1.10.1 ``` diff --git a/kotlinx-coroutines-core/build.gradle.kts b/kotlinx-coroutines-core/build.gradle.kts index d6abbd7e8a..b3921f659d 100644 --- a/kotlinx-coroutines-core/build.gradle.kts +++ b/kotlinx-coroutines-core/build.gradle.kts @@ -1,5 +1,3 @@ -import org.gradle.api.tasks.testing.* -import org.gradle.kotlin.dsl.* import org.jetbrains.kotlin.gradle.plugin.mpp.* import org.jetbrains.kotlin.gradle.targets.native.tasks.* import org.jetbrains.kotlin.gradle.tasks.* @@ -182,15 +180,23 @@ 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.trampoline") +} -fun setupManifest(jar: Jar) { +fun setupManifest(jar: Jar, autoModuleName: String? = null) { jar.manifest { - attributes(mapOf( + attributes( "Premain-Class" to "kotlinx.coroutines.debug.internal.AgentPremain", - "Can-Retransform-Classes" to "true", - )) + "Can-Retransform-Classes" to "true" + ) + autoModuleName?.also { + attributes("Automatic-Module-Name" to it) + } } } From a15ceb362814cb6719d1d8eb250fc145f905497d Mon Sep 17 00:00:00 2001 From: Filipp Zhinkin Date: Tue, 7 Jan 2025 09:45:57 -0500 Subject: [PATCH 2/2] Update the module name and clean up the code --- kotlinx-coroutines-core/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kotlinx-coroutines-core/build.gradle.kts b/kotlinx-coroutines-core/build.gradle.kts index b3921f659d..afebd53542 100644 --- a/kotlinx-coroutines-core/build.gradle.kts +++ b/kotlinx-coroutines-core/build.gradle.kts @@ -185,7 +185,7 @@ val jvmJar by tasks.getting(Jar::class) { setupManifest(this) } * an explicit automatic module name has to be specified in the manifest. */ val allMetadataJar by tasks.getting(Jar::class) { - setupManifest(this, "kotlinx.coroutines.core.trampoline") + setupManifest(this, "kotlinx.coroutines.core.artifact_disambiguating_module") } fun setupManifest(jar: Jar, autoModuleName: String? = null) { @@ -194,7 +194,7 @@ fun setupManifest(jar: Jar, autoModuleName: String? = null) { "Premain-Class" to "kotlinx.coroutines.debug.internal.AgentPremain", "Can-Retransform-Classes" to "true" ) - autoModuleName?.also { + autoModuleName?.let { attributes("Automatic-Module-Name" to it) } }