xref: /aosp_15_r20/external/kotlinx.coroutines/kotlinx-coroutines-debug/build.gradle.kts (revision 7a7160fed73afa6648ef8aa100d4a336fe921d9a)

<lambda>null1 import com.github.jengelman.gradle.plugins.shadow.tasks.*
2 import java.net.*
3 import java.nio.file.*
4 
5 plugins {
6     id("com.github.johnrengelman.shadow")
7     id("org.jetbrains.kotlinx.kover") // apply plugin to use autocomplete for Kover DSL
8 }
9 
<lambda>null10 configurations {
11     val shadowDeps by creating
12     compileOnly.configure {
13         extendsFrom(shadowDeps)
14     }
15     runtimeOnly.configure {
16         extendsFrom(shadowDeps)
17     }
18 }
19 
20 val junit_version by properties
21 val junit5_version by properties
22 val byte_buddy_version by properties
23 val blockhound_version by properties
24 val jna_version by properties
25 
<lambda>null26 dependencies {
27     compileOnly("junit:junit:$junit_version")
28     compileOnly("org.junit.jupiter:junit-jupiter-api:$junit5_version")
29     testImplementation("org.junit.jupiter:junit-jupiter-engine:$junit5_version")
30     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")
33     compileOnly("io.projectreactor.tools:blockhound:$blockhound_version")
34     testImplementation("io.projectreactor.tools:blockhound:$blockhound_version")
35     testImplementation("com.google.code.gson:gson:2.8.6")
36     api("net.java.dev.jna:jna:$jna_version")
37     api("net.java.dev.jna:jna-platform:$jna_version")
38 }
39 
<lambda>null40 java {
41     /* This is needed to be able to run JUnit5 tests. Otherwise, Gradle complains that it can't find the
42     JVM1.6-compatible version of the `junit-jupiter-api` artifact. */
43     disableAutoTargetJvm()
44 }
45 
46 // This is required for BlockHound tests to work, see https://github.com/Kotlin/kotlinx.coroutines/issues/3701
<lambda>null47 tasks.withType<Test>().configureEach {
48     if (JavaVersion.toVersion(jdkToolchainVersion).isCompatibleWith(JavaVersion.VERSION_13)) {
49         jvmArgs("-XX:+AllowRedefinitionToAddDeleteMethods")
50     }
51 }
52 
<lambda>null53 val jar by tasks.existing(Jar::class) {
54     enabled = false
55 }
56 
<lambda>null57 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 }
68     manifest {
69         attributes(
70             mapOf(
71                 "Premain-Class" to "kotlinx.coroutines.debug.AgentPremain",
72                 "Can-Redefine-Classes" to "true",
73                 "Multi-Release" to "true"
74             )
75         )
76     }
77     // add module-info.class to the META-INF/versions/9/ directory.
78     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         }
90     }
91 }
92 
<lambda>null93 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 
<lambda>null102 kover {
103     reports {
104         filters {
105             excludes {
106                 // Never used, safety mechanism
107                 classes("kotlinx.coroutines.debug.internal.NoOpProbesKt")
108             }
109         }
110     }
111 }
112