Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify Automatic-Module-Name for kotlinx-coroutines-core #4320

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Add dependencies (you can also add other modules that you need):
```xml
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<artifactId>kotlinx-coroutines-core-jvm</artifactId>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, -jvm is visual noise in this case and doesn't actually mean anything. Of course it's JVM, we're mentioning a Kotlin project in a Maven file. I understand that there's an extra dependency resolution step, but does it have any non-negligible effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that there's an extra dependency resolution step, but does it have any non-negligible effect?

Just trying to make the world better by saving ~130KB of networking traffic for each resolution when the artifact is not cached locally yet. :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, you're also adding 4 bytes to every load of the README file or the title page of kotlinx.coroutines; also, 4 bytes are going to be added to every version of README.md in the git repository starting from this PR (to be fair, those blob objects are compressed, so this is less critical).

<version>1.10.1</version>
</dependency>
```
Expand Down
20 changes: 13 additions & 7 deletions kotlinx-coroutines-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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.*
Expand Down Expand Up @@ -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.artifact_disambiguating_module")
}

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?.let {
attributes("Automatic-Module-Name" to it)
}
}
}

Expand Down