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..90a43a6b5c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,8 +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 android_version=4.1.1.4 diff --git a/kotlinx-coroutines-debug/README.md b/kotlinx-coroutines-debug/README.md index d3cb5267bc..27d8b5b9b7 100644 --- a/kotlinx-coroutines-debug/README.md +++ b/kotlinx-coroutines-debug/README.md @@ -167,12 +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. -* 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. +`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. One possible workaround for these issues is to add the following to the `android` block in your gradle file for the application subproject: diff --git a/kotlinx-coroutines-debug/build.gradle.kts b/kotlinx-coroutines-debug/build.gradle.kts index 1d0be22bfd..70f592a98e 100644 --- a/kotlinx-coroutines-debug/build.gradle.kts +++ b/kotlinx-coroutines-debug/build.gradle.kts @@ -1,22 +1,12 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.* -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("com.github.johnrengelman.shadow") 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 @@ -28,8 +18,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") @@ -50,21 +40,7 @@ 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 } +tasks.named("jar") { manifest { attributes( mapOf( @@ -74,30 +50,17 @@ val shadowJar by tasks.existing(ShadowJar::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") } } -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 {