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
4
5
5
6
plugins {
6
- id(" com.github.johnrengelman.shadow" )
7
7
id(" org.jetbrains.kotlinx.kover" ) // apply plugin to use autocomplete for Kover DSL
8
8
}
9
9
10
- configurations {
11
- val shadowDeps by creating
12
- compileOnly.configure {
13
- extendsFrom(shadowDeps)
14
- }
15
- runtimeOnly.configure {
16
- extendsFrom(shadowDeps)
17
- }
18
- }
19
-
20
10
val junit_version by properties
21
11
val junit5_version by properties
22
12
val byte_buddy_version by properties
@@ -28,8 +18,8 @@ dependencies {
28
18
compileOnly(" org.junit.jupiter:junit-jupiter-api:$junit5_version " )
29
19
testImplementation(" org.junit.jupiter:junit-jupiter-engine:$junit5_version " )
30
20
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 " )
33
23
compileOnly(" io.projectreactor.tools:blockhound:$blockhound_version " )
34
24
testImplementation(" io.projectreactor.tools:blockhound:$blockhound_version " )
35
25
testImplementation(" com.google.code.gson:gson:2.8.6" )
@@ -50,21 +40,7 @@ tasks.withType<Test>().configureEach {
50
40
}
51
41
}
52
42
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" ) {
68
44
manifest {
69
45
attributes(
70
46
mapOf (
@@ -74,30 +50,17 @@ val shadowJar by tasks.existing(ShadowJar::class) {
74
50
)
75
51
)
76
52
}
53
+
77
54
// add module-info.class to the META-INF/versions/9/ directory.
78
55
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" )
90
61
}
91
62
}
92
63
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
- }
101
64
102
65
kover {
103
66
reports {
0 commit comments