1- import com.github.jengelman.gradle.plugins.shadow.tasks.*
2- import java.net.*
3- import java.nio.file.*
1+ import org.gradle.api.JavaVersion
2+ import org.gradle.api.file.DuplicatesStrategy
3+ import org.gradle.api.tasks.bundling.Jar
4+ import org.gradle.api.tasks.testing.Test
45
56plugins {
6- id(" com.github.johnrengelman.shadow" )
77 id(" org.jetbrains.kotlinx.kover" ) // apply plugin to use autocomplete for Kover DSL
88}
99
10- configurations {
11- val shadowDeps by creating
12- compileOnly.configure {
13- extendsFrom(shadowDeps)
14- }
15- runtimeOnly.configure {
16- extendsFrom(shadowDeps)
17- }
18- }
19-
2010val junit_version by properties
2111val junit5_version by properties
2212val byte_buddy_version by properties
@@ -28,8 +18,8 @@ dependencies {
2818 compileOnly(" org.junit.jupiter:junit-jupiter-api:$junit5_version " )
2919 testImplementation(" org.junit.jupiter:junit-jupiter-engine:$junit5_version " )
3020 testImplementation(" org.junit.platform:junit-platform-testkit:1.7.0" )
31- add( " shadowDeps " , " net.bytebuddy:byte-buddy:$byte_buddy_version " )
32- add( " shadowDeps " , " net.bytebuddy:byte-buddy-agent:$byte_buddy_version " )
21+ implementation( " net.bytebuddy:byte-buddy:$byte_buddy_version " )
22+ implementation( " net.bytebuddy:byte-buddy-agent:$byte_buddy_version " )
3323 compileOnly(" io.projectreactor.tools:blockhound:$blockhound_version " )
3424 testImplementation(" io.projectreactor.tools:blockhound:$blockhound_version " )
3525 testImplementation(" com.google.code.gson:gson:2.8.6" )
@@ -50,21 +40,7 @@ tasks.withType<Test>().configureEach {
5040 }
5141}
5242
53- val jar by tasks.existing(Jar ::class ) {
54- enabled = false
55- }
56-
57- val shadowJar by tasks.existing(ShadowJar ::class ) {
58- // Shadow only byte buddy, do not package kotlin stdlib
59- configurations = listOf (project.configurations[" shadowDeps" ])
60- relocate(" net.bytebuddy" , " kotlinx.coroutines.repackaged.net.bytebuddy" )
61- /* These classifiers are both set to `null` to trick Gradle into thinking that this jar file is both the
62- artifact from the `jar` task and the one from `shadowJar`. Without this, Gradle complains that the artifact
63- from the `jar` task is not present when the compilaton finishes, even if the file with this name exists. */
64- archiveClassifier.convention(null as String? )
65- archiveClassifier = null
66- archiveBaseName = jar.flatMap { it.archiveBaseName }
67- archiveVersion = jar.flatMap { it.archiveVersion }
43+ tasks.named<Jar >(" jar" ) {
6844 manifest {
6945 attributes(
7046 mapOf (
@@ -74,30 +50,17 @@ val shadowJar by tasks.existing(ShadowJar::class) {
7450 )
7551 )
7652 }
53+
7754 // add module-info.class to the META-INF/versions/9/ directory.
7855 dependsOn(tasks.compileModuleInfoJava)
79- doLast {
80- // We can't do that directly with the shadowJar task because it doesn't support replacing existing files.
81- val zipPath = this @existing.outputs.files.singleFile.toPath()
82- val zipUri = URI .create(" jar:${zipPath.toUri()} " )
83- val moduleInfoFilePath = tasks.compileModuleInfoJava.get().outputs.files.asFileTree.matching {
84- include(" module-info.class" )
85- }.singleFile.toPath()
86- FileSystems .newFileSystem(zipUri, emptyMap<String , String >()).use { fs ->
87- val moduleInfoFile = fs.getPath(" META-INF/versions/9/module-info.class" )
88- Files .copy(moduleInfoFilePath, moduleInfoFile, StandardCopyOption .REPLACE_EXISTING )
89- }
56+ from(tasks.compileModuleInfoJava.get().outputs.files.asFileTree.matching {
57+ include(" module-info.class" )
58+ }) {
59+ this .duplicatesStrategy = DuplicatesStrategy .INCLUDE
60+ into(" META-INF/versions/9" )
9061 }
9162}
9263
93- configurations {
94- // shadowJar is already part of the `shadowRuntimeElements` and `shadowApiElements`, but the other subprojects
95- // that depend on `kotlinx-coroutines-debug` look at `runtimeElements` and `apiElements`.
96- artifacts {
97- add(" apiElements" , shadowJar)
98- add(" runtimeElements" , shadowJar)
99- }
100- }
10164
10265kover {
10366 reports {
0 commit comments