From 6745a556b91acfa3c89f65e9a742ce50dd38c392 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Mon, 4 Nov 2024 14:41:13 +0100 Subject: [PATCH 1/9] Declare byte-buddy as 'implementation' dependency instead of shading. Shading byte buddy might have negative effects: - It increases binary size by ~3MB w/o an easy option to opt-out - It causes JPMS issues (because of the re-location itself) The used APIs from the dependency can be considered stable. --- kotlinx-coroutines-debug/build.gradle.kts | 28 ++--------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/kotlinx-coroutines-debug/build.gradle.kts b/kotlinx-coroutines-debug/build.gradle.kts index 1d0be22bfd..8c465a273d 100644 --- a/kotlinx-coroutines-debug/build.gradle.kts +++ b/kotlinx-coroutines-debug/build.gradle.kts @@ -1,9 +1,7 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.* import java.net.* import java.nio.file.* plugins { - id("com.github.johnrengelman.shadow") id("org.jetbrains.kotlinx.kover") // apply plugin to use autocomplete for Kover DSL } @@ -28,8 +26,8 @@ dependencies { compileOnly("org.junit.jupiter:junit-jupiter-api:$junit5_version") testImplementation("org.junit.jupiter:junit-jupiter-engine:$junit5_version") testImplementation("org.junit.platform:junit-platform-testkit:1.7.0") - add("shadowDeps", "net.bytebuddy:byte-buddy:$byte_buddy_version") - add("shadowDeps", "net.bytebuddy:byte-buddy-agent:$byte_buddy_version") + implementation("net.bytebuddy:byte-buddy:$byte_buddy_version") + implementation("net.bytebuddy:byte-buddy-agent:$byte_buddy_version") compileOnly("io.projectreactor.tools:blockhound:$blockhound_version") testImplementation("io.projectreactor.tools:blockhound:$blockhound_version") testImplementation("com.google.code.gson:gson:2.8.6") @@ -51,20 +49,6 @@ tasks.withType().configureEach { } val jar by tasks.existing(Jar::class) { - enabled = false -} - -val shadowJar by tasks.existing(ShadowJar::class) { - // Shadow only byte buddy, do not package kotlin stdlib - configurations = listOf(project.configurations["shadowDeps"]) - relocate("net.bytebuddy", "kotlinx.coroutines.repackaged.net.bytebuddy") - /* These classifiers are both set to `null` to trick Gradle into thinking that this jar file is both the - artifact from the `jar` task and the one from `shadowJar`. Without this, Gradle complains that the artifact - from the `jar` task is not present when the compilaton finishes, even if the file with this name exists. */ - archiveClassifier.convention(null as String?) - archiveClassifier = null - archiveBaseName = jar.flatMap { it.archiveBaseName } - archiveVersion = jar.flatMap { it.archiveVersion } manifest { attributes( mapOf( @@ -90,14 +74,6 @@ val shadowJar by tasks.existing(ShadowJar::class) { } } -configurations { - // shadowJar is already part of the `shadowRuntimeElements` and `shadowApiElements`, but the other subprojects - // that depend on `kotlinx-coroutines-debug` look at `runtimeElements` and `apiElements`. - artifacts { - add("apiElements", shadowJar) - add("runtimeElements", shadowJar) - } -} kover { reports { From 532900d75600facc6569bd8657bfbb01ad5179a3 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Mon, 4 Nov 2024 14:48:50 +0100 Subject: [PATCH 2/9] fixup! Declare byte-buddy as 'implementation' dependency instead of shading. --- kotlinx-coroutines-debug/build.gradle.kts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/kotlinx-coroutines-debug/build.gradle.kts b/kotlinx-coroutines-debug/build.gradle.kts index 8c465a273d..7d194044b5 100644 --- a/kotlinx-coroutines-debug/build.gradle.kts +++ b/kotlinx-coroutines-debug/build.gradle.kts @@ -1,5 +1,7 @@ -import java.net.* -import java.nio.file.* +import org.gradle.api.JavaVersion +import org.gradle.api.file.DuplicatesStrategy +import org.gradle.api.tasks.bundling.Jar +import org.gradle.api.tasks.testing.Test plugins { id("org.jetbrains.kotlinx.kover") // apply plugin to use autocomplete for Kover DSL @@ -58,19 +60,14 @@ val jar by tasks.existing(Jar::class) { ) ) } + // add module-info.class to the META-INF/versions/9/ directory. dependsOn(tasks.compileModuleInfoJava) - doLast { - // We can't do that directly with the shadowJar task because it doesn't support replacing existing files. - val zipPath = this@existing.outputs.files.singleFile.toPath() - val zipUri = URI.create("jar:${zipPath.toUri()}") - val moduleInfoFilePath = tasks.compileModuleInfoJava.get().outputs.files.asFileTree.matching { - include("module-info.class") - }.singleFile.toPath() - FileSystems.newFileSystem(zipUri, emptyMap()).use { fs -> - val moduleInfoFile = fs.getPath("META-INF/versions/9/module-info.class") - Files.copy(moduleInfoFilePath, moduleInfoFile, StandardCopyOption.REPLACE_EXISTING) - } + from(tasks.compileModuleInfoJava.get().outputs.files.asFileTree.matching { + include("module-info.class") + }) { + this.duplicatesStrategy = DuplicatesStrategy.INCLUDE + into("META-INF/versions/9") } } From 5ef5b783a881fe20f9e70794e9ff100fbf75fbe0 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Mon, 4 Nov 2024 14:50:55 +0100 Subject: [PATCH 3/9] fixup! Declare byte-buddy as 'implementation' dependency instead of shading. --- kotlinx-coroutines-debug/build.gradle.kts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/kotlinx-coroutines-debug/build.gradle.kts b/kotlinx-coroutines-debug/build.gradle.kts index 7d194044b5..a9a906c2eb 100644 --- a/kotlinx-coroutines-debug/build.gradle.kts +++ b/kotlinx-coroutines-debug/build.gradle.kts @@ -7,16 +7,6 @@ plugins { id("org.jetbrains.kotlinx.kover") // apply plugin to use autocomplete for Kover DSL } -configurations { - val shadowDeps by creating - compileOnly.configure { - extendsFrom(shadowDeps) - } - runtimeOnly.configure { - extendsFrom(shadowDeps) - } -} - val junit_version by properties val junit5_version by properties val byte_buddy_version by properties From 4ce02e099b25da7d74eb5f70e815da27043a11ff Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Mon, 4 Nov 2024 14:51:42 +0100 Subject: [PATCH 4/9] fixup! Declare byte-buddy as 'implementation' dependency instead of shading. --- kotlinx-coroutines-debug/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kotlinx-coroutines-debug/build.gradle.kts b/kotlinx-coroutines-debug/build.gradle.kts index a9a906c2eb..70f592a98e 100644 --- a/kotlinx-coroutines-debug/build.gradle.kts +++ b/kotlinx-coroutines-debug/build.gradle.kts @@ -40,7 +40,7 @@ tasks.withType().configureEach { } } -val jar by tasks.existing(Jar::class) { +tasks.named("jar") { manifest { attributes( mapOf( From ff72c9dfd9848846164481dd31793c9d9e110886 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Thu, 7 Nov 2024 17:04:36 +0100 Subject: [PATCH 5/9] fixup! Declare byte-buddy as 'implementation' dependency instead of shading. --- kotlinx-coroutines-debug/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/kotlinx-coroutines-debug/README.md b/kotlinx-coroutines-debug/README.md index d3cb5267bc..f910000c7b 100644 --- a/kotlinx-coroutines-debug/README.md +++ b/kotlinx-coroutines-debug/README.md @@ -170,9 +170,6 @@ conflicts, but: * `kotlinx-coroutines-debug` transitively depends on JNA and JNA-platform, both of which include license files in their META-INF directories. Trying to merge these files leads to conflicts, which means that any Android project that depends on JNA and JNA-platform will experience build failures. -* Additionally, `kotlinx-coroutines-debug` embeds `byte-buddy-agent` and `byte-buddy`, along with their resource files. - Then, if the project separately depends on `byte-buddy`, merging the resources of `kotlinx-coroutines-debug` with ones - from `byte-buddy` and `byte-buddy-agent` will lead to conflicts as the resource files are duplicated. One possible workaround for these issues is to add the following to the `android` block in your gradle file for the application subproject: From 647824126b9b78aa5e6c2d77c8d2cb865c40f0df Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Thu, 14 Nov 2024 07:29:32 +0100 Subject: [PATCH 6/9] fixup! Declare byte-buddy as 'implementation' dependency instead of shading. --- kotlinx-coroutines-debug/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kotlinx-coroutines-debug/README.md b/kotlinx-coroutines-debug/README.md index f910000c7b..7d3edfdf39 100644 --- a/kotlinx-coroutines-debug/README.md +++ b/kotlinx-coroutines-debug/README.md @@ -167,9 +167,9 @@ dependency of `kotlinx-coroutines-test`) may fail with `DuplicateRelativeFileExc The problem is that Android merges the resources of all its dependencies into a single directory and complains about conflicts, but: -* `kotlinx-coroutines-debug` transitively depends on JNA and JNA-platform, both of which include license files in their - META-INF directories. Trying to merge these files leads to conflicts, which means that any Android project that - depends on JNA and JNA-platform will experience build failures. +`kotlinx-coroutines-debug` transitively depends on JNA and JNA-platform, byte-buddy and byte-buddy-agent, both of which include license files in their +META-INF directories. Trying to merge these files leads to conflicts, which means that any Android project that +depends on JNA and JNA-platform will experience build failures. One possible workaround for these issues is to add the following to the `android` block in your gradle file for the application subproject: From 4aa1b99a1f4811f6f84ef1d3f74865f95388270a Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Thu, 14 Nov 2024 07:30:41 +0100 Subject: [PATCH 7/9] fixup! Declare byte-buddy as 'implementation' dependency instead of shading. --- kotlinx-coroutines-debug/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kotlinx-coroutines-debug/README.md b/kotlinx-coroutines-debug/README.md index 7d3edfdf39..27d8b5b9b7 100644 --- a/kotlinx-coroutines-debug/README.md +++ b/kotlinx-coroutines-debug/README.md @@ -167,7 +167,7 @@ dependency of `kotlinx-coroutines-test`) may fail with `DuplicateRelativeFileExc The problem is that Android merges the resources of all its dependencies into a single directory and complains about conflicts, but: -`kotlinx-coroutines-debug` transitively depends on JNA and JNA-platform, byte-buddy and byte-buddy-agent, both of which include license files in their +`kotlinx-coroutines-debug` transitively depends on JNA and JNA-platform, byte-buddy and byte-buddy-agent, all of them include license files in their META-INF directories. Trying to merge these files leads to conflicts, which means that any Android project that depends on JNA and JNA-platform will experience build failures. From c10a35d78b5ad67098102cfcd70bc773523aacbe Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Mon, 18 Nov 2024 07:21:31 +0100 Subject: [PATCH 8/9] Remove shadow plugin from build --- benchmarks/build.gradle.kts | 1 - build.gradle.kts | 3 --- buildSrc/src/main/kotlin/version-file-conventions.gradle.kts | 4 ---- gradle.properties | 1 - 4 files changed, 9 deletions(-) diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts index 7006c915d9..2b124f6208 100644 --- a/benchmarks/build.gradle.kts +++ b/benchmarks/build.gradle.kts @@ -4,7 +4,6 @@ import org.jetbrains.kotlin.gradle.tasks.* import org.jetbrains.kotlin.gradle.dsl.JvmTarget plugins { - id("com.github.johnrengelman.shadow") id("me.champeau.jmh") } diff --git a/build.gradle.kts b/build.gradle.kts index caef1260ac..dc4a7f12f6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -27,9 +27,6 @@ buildscript { classpath("ru.vyarus:gradle-animalsniffer-plugin:${version("animalsniffer")}") // Android API check classpath("org.jetbrains.kotlin:atomicfu:${version("kotlin")}") classpath("org.jetbrains.kotlinx:kover-gradle-plugin:${version("kover")}") - - // JMH plugins - classpath("gradle.plugin.com.github.johnrengelman:shadow:${version("shadow")}") } with(CacheRedirector) { buildscript.configureBuildScript(rootProject) } diff --git a/buildSrc/src/main/kotlin/version-file-conventions.gradle.kts b/buildSrc/src/main/kotlin/version-file-conventions.gradle.kts index 587e184b30..5a807ef5a7 100644 --- a/buildSrc/src/main/kotlin/version-file-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/version-file-conventions.gradle.kts @@ -3,10 +3,6 @@ import org.gradle.api.tasks.bundling.* configure(subprojects.filter { !unpublished.contains(it.name) && it.name !in sourceless }) { val project = this val jarTaskName = when { - project.name == "kotlinx-coroutines-debug" -> { - project.apply(plugin = "com.github.johnrengelman.shadow") - "shadowJar" - } isMultiplatform -> "jvmJar" else -> "jar" } diff --git a/gradle.properties b/gradle.properties index 168fb6b6c5..ef02084ef1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,6 @@ jna_version=5.9.0 # Gradle jdk_toolchain_version=11 animalsniffer_version=1.7.1 -shadow_version=7.1.2 #shadow_version=8.1.1 For Gradle 8, not compatible with Gradle 7 # Android versions From 94807151e40b9a6670e8d488d4b3e0c4a161af5a Mon Sep 17 00:00:00 2001 From: Dmitry Khalanskiy Date: Mon, 18 Nov 2024 12:46:37 +0100 Subject: [PATCH 9/9] Remove a leftover --- gradle.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ef02084ef1..90a43a6b5c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,6 @@ jna_version=5.9.0 # Gradle jdk_toolchain_version=11 animalsniffer_version=1.7.1 -#shadow_version=8.1.1 For Gradle 8, not compatible with Gradle 7 # Android versions android_version=4.1.1.4