Louis Pullen-Freilich | 834c8a9 | 2019-05-07 15:00:30 +0100 | [diff] [blame] | 1 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
| 2 | |
Sergey Vasilinets | 70a2e82 | 2017-11-03 12:20:28 -0700 | [diff] [blame] | 3 | buildscript { |
Jeff Gaston | fb6f844 | 2020-05-26 17:53:58 -0400 | [diff] [blame] | 4 | project.ext.supportRootFolder = project.projectDir.getParentFile() |
Sergey Vasilinets | 70a2e82 | 2017-11-03 12:20:28 -0700 | [diff] [blame] | 5 | repositories { |
| 6 | maven { |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 7 | url("${supportRootFolder}/../../prebuilts/androidx/external") |
Jeff Gaston | db2929e | 2018-03-07 13:52:32 -0500 | [diff] [blame] | 8 | } |
Sergey Vasilinets | 70a2e82 | 2017-11-03 12:20:28 -0700 | [diff] [blame] | 9 | } |
Sergey Vasilinets | ccb3fcb | 2017-10-16 23:46:48 +0000 | [diff] [blame] | 10 | |
Sergey Vasilinets | 70a2e82 | 2017-11-03 12:20:28 -0700 | [diff] [blame] | 11 | apply from: "build_dependencies.gradle" |
| 12 | |
| 13 | dependencies { |
| 14 | classpath build_libs.kotlin.gradle_plugin |
| 15 | } |
Jake Wharton | 7495cc1 | 2018-01-05 11:05:13 -0500 | [diff] [blame] | 16 | |
| 17 | configurations.classpath.resolutionStrategy { |
| 18 | eachDependency { details -> |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 19 | if (details.requested.group == "org.jetbrains.kotlin") { |
Jake Wharton | 7495cc1 | 2018-01-05 11:05:13 -0500 | [diff] [blame] | 20 | details.useVersion build_versions.kotlin |
| 21 | } |
| 22 | } |
| 23 | } |
Sergey Vasilinets | 70a2e82 | 2017-11-03 12:20:28 -0700 | [diff] [blame] | 24 | } |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 25 | |
| 26 | apply from: "out.gradle" |
| 27 | init.chooseOutDir() |
| 28 | |
Aurimas Liutikas | 9ab3b4c3 | 2017-04-19 09:33:27 -0700 | [diff] [blame] | 29 | ext.supportRootFolder = project.projectDir.getParentFile() |
Jeff Gaston | fef185a | 2020-02-05 11:48:53 -0500 | [diff] [blame] | 30 | apply from: "local_dokka.gradle" |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 31 | apply from: "repos.gradle" |
Aurimas Liutikas | 36bbc1d | 2018-01-24 19:32:16 -0800 | [diff] [blame] | 32 | apply from: "build_dependencies.gradle" |
Sergey Vasilinets | 164c38d | 2018-02-02 00:50:57 -0800 | [diff] [blame] | 33 | apply plugin: "kotlin" |
Jeff Gaston | 9cfb0a1 | 2019-11-06 17:50:14 -0500 | [diff] [blame] | 34 | apply from: "kotlin-dsl-dependency.gradle" |
Aurimas Liutikas | 9ab3b4c3 | 2017-04-19 09:33:27 -0700 | [diff] [blame] | 35 | |
Oussama Ben Abdelbaki | f825eb5 | 2018-12-04 16:17:00 -0500 | [diff] [blame] | 36 | allprojects { |
| 37 | repos.addMavenRepositories(repositories) |
Jake Wharton | a0576c3 | 2018-07-27 13:09:42 -0400 | [diff] [blame] | 38 | |
Louis Pullen-Freilich | 834c8a9 | 2019-05-07 15:00:30 +0100 | [diff] [blame] | 39 | tasks.withType(KotlinCompile).configureEach { |
| 40 | kotlinOptions { |
Aurimas Liutikas | 4c59026 | 2019-10-17 14:55:22 -0700 | [diff] [blame] | 41 | jvmTarget = "1.8" |
Alan Viverette | 5baaf85 | 2020-06-04 16:10:19 +0000 | [diff] [blame] | 42 | freeCompilerArgs += [ |
| 43 | "-Werror", |
| 44 | "-Xskip-runtime-version-check", |
Jim Sproch | a88c07a | 2020-06-25 13:00:03 -0700 | [diff] [blame] | 45 | "-Xskip-metadata-version-check", |
Alan Viverette | 5baaf85 | 2020-06-04 16:10:19 +0000 | [diff] [blame] | 46 | // Allow `@OptIn` and `@UseExperimental` |
| 47 | "-Xopt-in=kotlin.RequiresOptIn" |
| 48 | ] |
Louis Pullen-Freilich | 834c8a9 | 2019-05-07 15:00:30 +0100 | [diff] [blame] | 49 | } |
| 50 | } |
Oussama Ben Abdelbaki | f825eb5 | 2018-12-04 16:17:00 -0500 | [diff] [blame] | 51 | } |
Sergey Vasilinets | bb245e08 | 2017-10-11 00:16:04 -0700 | [diff] [blame] | 52 | |
Jeff Gaston | 1e27f97 | 2020-04-20 11:27:17 -0400 | [diff] [blame] | 53 | configurations { |
| 54 | // Dependencies added to these configurations get copied into the corresponding configuration |
| 55 | // (cacheableApi gets copied into api, etc). |
| 56 | // Because we cache the resolutions of these configurations, performance is faster when |
| 57 | // artifacts are put into these configurations than when those artifacts are put into their |
| 58 | // corresponding configuration. |
| 59 | cacheableApi |
| 60 | cacheableImplementation { |
| 61 | extendsFrom(project.configurations.cacheableApi) |
| 62 | } |
Jeff Gaston | 9093c15 | 2020-12-03 11:23:05 -0500 | [diff] [blame] | 63 | cacheableRuntimeOnly |
Jeff Gaston | 1e27f97 | 2020-04-20 11:27:17 -0400 | [diff] [blame] | 64 | } |
| 65 | |
Aurimas Liutikas | 9697da7 | 2016-12-22 15:50:42 -0800 | [diff] [blame] | 66 | dependencies { |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 67 | cacheableApi(build_libs.agp) |
| 68 | cacheableImplementation(build_libs.dex_member_list) |
| 69 | cacheableApi(build_libs.kotlin.gradle_plugin) |
| 70 | cacheableImplementation(build_libs.kotlinpoet) |
| 71 | cacheableImplementation(gradleApi()) |
| 72 | cacheableApi(build_libs.dokka_gradle) |
Sergey Vasilinets | 95f91db | 2020-01-13 20:21:29 +0000 | [diff] [blame] | 73 | // needed by inspection plugin |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 74 | cacheableImplementation("com.google.protobuf:protobuf-gradle-plugin:0.8.13") |
Chris Craik | 3a06f1e | 2021-04-22 10:47:29 -0700 | [diff] [blame] | 75 | cacheableImplementation(build_libs.wire_plugin) |
Sergey Vasilinets | 0256f57 | 2020-12-02 14:06:40 +0000 | [diff] [blame] | 76 | // TODO(aurimas): remove when b/174658825 is fixed |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 77 | cacheableImplementation("org.anarres.jarjar:jarjar-gradle:1.0.1") |
Aurimas Liutikas | c1a597b | 2021-04-20 11:05:38 -0700 | [diff] [blame] | 78 | cacheableImplementation(build_libs.shadow) |
Jeff Gaston | 1e27f97 | 2020-04-20 11:27:17 -0400 | [diff] [blame] | 79 | // dependencies that aren't used by buildSrc directly but that we resolve here so that the |
| 80 | // root project doesn't need to re-resolve them and their dependencies on every build |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 81 | cacheableRuntimeOnly(build_libs.hilt_plugin) |
Yigit Boyar | 23758df | 2020-12-16 18:47:29 -0800 | [diff] [blame] | 82 | // room kotlintestapp uses the ksp plugin but it does not publish a plugin marker yet |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 83 | cacheableRuntimeOnly(build_libs.kotlin.ksp_gradle_plugin) |
Jeff Gaston | 1e27f97 | 2020-04-20 11:27:17 -0400 | [diff] [blame] | 84 | // dependencies whose resolutions we don't need to cache |
| 85 | compileOnly(findGradleKotlinDsl()) // Only one file in this configuration, no need to cache it |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 86 | implementation(project("jetpad-integration")) // Doesn't have a .pom, so not slow to load |
Jeff Gaston | 1e27f97 | 2020-04-20 11:27:17 -0400 | [diff] [blame] | 87 | } |
| 88 | |
Dustin Lam | 56130b2 | 2019-07-26 17:17:09 -0700 | [diff] [blame] | 89 | apply plugin: "java-gradle-plugin" |
| 90 | |
| 91 | sourceSets { |
| 92 | main.java.srcDirs += "${supportRootFolder}/benchmark/gradle-plugin/src/main/kotlin" |
| 93 | main.resources.srcDirs += "${supportRootFolder}/benchmark/gradle-plugin/src/main/resources" |
Sergey Vasilinets | 4e97056 | 2019-12-12 13:39:19 +0000 | [diff] [blame] | 94 | |
| 95 | main.java.srcDirs += "${supportRootFolder}/inspection/inspection-gradle-plugin/src/main/kotlin" |
| 96 | main.resources.srcDirs += "${supportRootFolder}/inspection/inspection-gradle-plugin/src/main" + |
| 97 | "/resources" |
Louis Pullen-Freilich | 5c6b11e | 2020-02-06 18:19:09 +0000 | [diff] [blame] | 98 | |
Louis Pullen-Freilich | ba7da08 | 2020-08-13 21:07:12 +0100 | [diff] [blame] | 99 | main.java.srcDirs += "${supportRootFolder}/compose/material/material/icons/generator/src/main" + |
| 100 | "/kotlin" |
Dustin Lam | 56130b2 | 2019-07-26 17:17:09 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | gradlePlugin { |
| 104 | plugins { |
| 105 | benchmark { |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 106 | id = "androidx.benchmark" |
| 107 | implementationClass = "androidx.benchmark.gradle.BenchmarkPlugin" |
Dustin Lam | 56130b2 | 2019-07-26 17:17:09 -0700 | [diff] [blame] | 108 | } |
Sergey Vasilinets | 4e97056 | 2019-12-12 13:39:19 +0000 | [diff] [blame] | 109 | inspection { |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 110 | id = "androidx.inspection" |
| 111 | implementationClass = "androidx.inspection.gradle.InspectionPlugin" |
Sergey Vasilinets | 4e97056 | 2019-12-12 13:39:19 +0000 | [diff] [blame] | 112 | } |
Dustin Lam | 56130b2 | 2019-07-26 17:17:09 -0700 | [diff] [blame] | 113 | } |
Jeff Gaston | 9cfb0a1 | 2019-11-06 17:50:14 -0500 | [diff] [blame] | 114 | } |
Jeff Gaston | 911812e | 2020-05-01 19:59:43 -0400 | [diff] [blame] | 115 | |
| 116 | // Saves configuration into destFile |
| 117 | // Each line of destFile will be the absolute filepath of one of the files in configuration |
| 118 | def saveConfigurationResolution(configuration, destFile) { |
| 119 | def resolvedConfiguration = configuration.resolvedConfiguration |
| 120 | def files = resolvedConfiguration.files |
| 121 | def paths = files.collect { f -> f.toString() } |
| 122 | def serialized = paths.join("\n") |
| 123 | destFile.text = serialized |
| 124 | } |
| 125 | |
| 126 | // Parses a file into a list of Dependency objects representing a ResolvedConfiguration |
| 127 | def parseConfigurationResolution(savedFile) { |
| 128 | def savedText = savedFile.text |
| 129 | def filenames = savedText.split("\n") |
| 130 | def dependencies = filenames.collect { filename -> |
| 131 | project.dependencies.create(project.files(filename)) |
| 132 | } |
| 133 | return dependencies |
| 134 | } |
| 135 | |
| 136 | // Resolves a Configuration into a list of Dependency objects |
| 137 | def resolveConfiguration(configuration) { |
| 138 | def resolvedName = configuration.name |
| 139 | def cacheDir = new File(project.buildDir, "/" + resolvedName) |
| 140 | def inputsFile = new File(cacheDir, "/deps") |
| 141 | def outputsFile = new File(cacheDir, "/result") |
| 142 | |
| 143 | def inputText = fingerprintConfiguration(configuration) |
| 144 | if (!inputsFile.exists() || inputsFile.text != inputText) { |
| 145 | cacheDir.mkdirs() |
| 146 | saveConfigurationResolution(configuration, outputsFile) |
| 147 | inputsFile.text = inputText |
| 148 | } |
| 149 | def result = parseConfigurationResolution(outputsFile) |
| 150 | return result |
| 151 | } |
| 152 | |
| 153 | // Computes a unique string from a Configuration based on its dependencies |
| 154 | // This is used for up-to-date checks |
| 155 | def fingerprintConfiguration(configuration) { |
| 156 | def dependencies = configuration.allDependencies |
| 157 | def dependencyTexts = dependencies.collect { dep -> dep.group + ":" + dep.name + ":" + dep.version } |
| 158 | return dependencyTexts.join("\n") |
| 159 | } |
| 160 | |
| 161 | // Imports the contents of fromConf into toConf |
| 162 | // Uses caching to often short-circuit the resolution of fromConf |
| 163 | def loadConfigurationQuicklyInto(fromConf, toConf) { |
| 164 | def resolved = resolveConfiguration(fromConf) |
| 165 | resolved.each { dep -> |
| 166 | project.dependencies.add(toConf.name, dep) |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | loadConfigurationQuicklyInto(configurations.cacheableApi, configurations.api) |
| 171 | loadConfigurationQuicklyInto(configurations.cacheableImplementation, configurations.implementation) |
Jeff Gaston | 9093c15 | 2020-12-03 11:23:05 -0500 | [diff] [blame] | 172 | loadConfigurationQuicklyInto(configurations.cacheableRuntimeOnly, configurations.runtimeOnly) |
Jeff Gaston | 52d044a | 2020-06-12 18:19:29 -0400 | [diff] [blame] | 173 | |
| 174 | project.tasks.withType(Jar) { task -> |
| 175 | task.reproducibleFileOrder = true |
| 176 | task.preserveFileTimestamps = false |
| 177 | } |