• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 import CacheRedirector.configure
2 import org.gradle.api.Project
3 import org.gradle.api.tasks.*
4 import org.gradle.kotlin.dsl.*
5 
6 /**
7  * Auxiliary build configuration that is grouped in a single place for convenience:
8  * - Workarounds for Gradle/KGP issues
9  * - Cache redirector
10  */
11 object AuxBuildConfiguration {
12 
13     @JvmStatic
configurenull14     fun configure(rootProject: Project) {
15         rootProject.allprojects {
16             workaroundForCleanTask()
17             CacheRedirector.configure(this)
18             workaroundForCoroutinesLeakageToClassPath()
19         }
20 
21         CacheRedirector.configureJsPackageManagers(rootProject)
22 
23         // Sigh, there is no BuildScanExtension in classpath when there is no --scan
24         rootProject.extensions.findByName("buildScan")?.withGroovyBuilder {
25             setProperty("termsOfServiceUrl", "https://gradle.com/terms-of-service")
26             setProperty("termsOfServiceAgree", "yes")
27         }
28     }
29 
Projectnull30     private fun Project.workaroundForCleanTask() {
31         // the 'clean' task cannot delete expanded.lock file on Windows as it is still held by Gradle, failing the build
32         // Gradle issue: https://github.com/gradle/gradle/issues/25752
33         tasks {
34             val clean by existing(Delete::class) {
35                 setDelete(fileTree(layout.buildDirectory) {
36                     exclude("tmp/.cache/expanded/expanded.lock")
37                 })
38             }
39         }
40     }
41 
42     /*
43      * 'kotlinx-coroutines-core' dependency leaks into test runtime classpath via 'kotlin-compiler-embeddable'
44      * and conflicts with our own test/runtime incompatibilities (e.g. when class is moved from a main to test),
45      * so we do substitution here.
46      * TODO figure out if it's still the problem
47      */
Projectnull48     private fun Project.workaroundForCoroutinesLeakageToClassPath() {
49         configurations
50             .matching {
51                 // Excluding substituted project itself because of circular dependencies, but still do it
52                 // for "*Test*" configurations
53                 name != coreModule || it.name.contains("Test")
54             }
55             .configureEach {
56                 resolutionStrategy.dependencySubstitution {
57                     substitute(module("org.jetbrains.kotlinx:$coreModule"))
58                         .using(project(":$coreModule"))
59                         .because(
60                             "Because Kotlin compiler embeddable leaks coroutines into the runtime classpath, " +
61                                 "triggering all sort of incompatible class changes errors"
62                         )
63                 }
64             }
65     }
66 }
67