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

Fix debug module publication with shadow plugin #3357

Merged
merged 7 commits into from Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions gradle/publish.gradle
Expand Up @@ -45,11 +45,7 @@ publishing {
// Configure java publications for regular non-MPP modules
publications {
maven(MavenPublication) {
if (project.name == "kotlinx-coroutines-debug") {
project.shadow.component(it)
} else {
from components.java
}
from components.java
artifact sourcesJar
}
}
Expand Down
18 changes: 9 additions & 9 deletions kotlinx-coroutines-debug/build.gradle
Expand Up @@ -8,14 +8,6 @@ configurations {
shadowDeps // shaded dependencies, not included into the resulting .pom file
compileOnly.extendsFrom(shadowDeps)
runtimeOnly.extendsFrom(shadowDeps)

/*
* It is possible to extend a particular configuration with shadow,
* but in that case it changes dependency type to "runtime" and resolves it
* (so it cannot be further modified). Otherwise, shadow just ignores all dependencies.
*/
shadow.extendsFrom(api) // shadow - resulting configuration with shaded jar file
configureKotlinJvmPlatform(shadow)
}

dependencies {
Expand All @@ -39,19 +31,27 @@ java {
}

jar {
setEnabled(false)
manifest {
attributes "Premain-Class": "kotlinx.coroutines.debug.AgentPremain"
attributes "Can-Redefine-Classes": "true"
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find this very counterintuitive: if a task is not enabled, why does its configuration contribute to anything? I propose to move the manifest block to shadowJar. If I understood correctly (and from a quick check of the resulting META-INF/MANIFEST.MF in the published JAR), this shouldn't change the result, but it would look much more clear.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Checking further, I see that this line was lost from the manifest compared to the one published to Maven Central:

Class-Path: kotlinx-coroutines-core-jvm-1.6.3.jar jna-platform-5.9.0.jar
  jna-5.9.0.jar kotlin-stdlib-jdk8-1.6.21.jar kotlin-stdlib-jdk7-1.6.21.
 jar kotlin-stdlib-1.6.21.jar kotlin-stdlib-common-1.6.21.jar annotation
 s-13.0.jar

However, deleting the locally-published repo and reverting my change, I can't make this line return. No idea what's going on.

Copy link
Member Author

Choose a reason for hiding this comment

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

Shadow jar extends the original jar task. Moved it to JAR task, it seems like the resulting published JAR contains the correct manifest.

It still worth to check it during the release tho

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's what I was proposing to do, but then I noticed the Class-Path line disappearing from the manifest.

Copy link
Member Author

Choose a reason for hiding this comment

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

The previous version also does not generate Class-Path attribute.
This is a nice catch, though I cannot convince myself that it actually ever affected anything.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is what I observed as well, yes, just wasn't sure.

Could you please try using the debug module in a minimal project as a dependency and check that everything still works, just to be safe? We do have integration tests for using it as a Java agent, but not for just using DebugProbes, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Restored it back, created #3361

Will push integration test soon as well


shadowJar {
def shadowJarTask = shadowJar {
classifier null
// Shadow only byte buddy, do not package kotlin stdlib
configurations = [project.configurations.shadowDeps]
relocate('net.bytebuddy', 'kotlinx.coroutines.repackaged.net.bytebuddy')
}

configurations {
artifacts {
add("apiElements", shadowJarTask)
add("runtimeElements", shadowJarTask)
}
}

def commonKoverExcludes =
// Never used, safety mechanism
["kotlinx.coroutines.debug.internal.NoOpProbesKt"]
Expand Down