blob: 9e2ccc41a6c38292d59adf7561ef21c68987752f [file] [log] [blame]
Louis Pullen-Freilich834c8a92019-05-07 15:00:30 +01001import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2
Sergey Vasilinets70a2e822017-11-03 12:20:28 -07003buildscript {
Jeff Gastonfb6f8442020-05-26 17:53:58 -04004 project.ext.supportRootFolder = project.projectDir.getParentFile()
Sergey Vasilinets70a2e822017-11-03 12:20:28 -07005 repositories {
6 maven {
Jim Sproch9e38b4f2021-01-06 14:21:06 -08007 url("${supportRootFolder}/../../prebuilts/androidx/external")
Jeff Gastondb2929e2018-03-07 13:52:32 -05008 }
Sergey Vasilinets70a2e822017-11-03 12:20:28 -07009 }
Sergey Vasilinetsccb3fcb2017-10-16 23:46:48 +000010
Sergey Vasilinets70a2e822017-11-03 12:20:28 -070011 apply from: "build_dependencies.gradle"
12
13 dependencies {
14 classpath build_libs.kotlin.gradle_plugin
15 }
Jake Wharton7495cc12018-01-05 11:05:13 -050016
17 configurations.classpath.resolutionStrategy {
18 eachDependency { details ->
Jim Sproch9e38b4f2021-01-06 14:21:06 -080019 if (details.requested.group == "org.jetbrains.kotlin") {
Jake Wharton7495cc12018-01-05 11:05:13 -050020 details.useVersion build_versions.kotlin
21 }
22 }
23 }
Sergey Vasilinets70a2e822017-11-03 12:20:28 -070024}
Jeff Gaston79a43f22019-04-09 16:19:12 -040025
26apply from: "out.gradle"
27init.chooseOutDir()
28
Aurimas Liutikas9ab3b4c32017-04-19 09:33:27 -070029ext.supportRootFolder = project.projectDir.getParentFile()
Jeff Gastonfef185a2020-02-05 11:48:53 -050030apply from: "local_dokka.gradle"
Jim Sproch9e38b4f2021-01-06 14:21:06 -080031apply from: "repos.gradle"
Aurimas Liutikas36bbc1d2018-01-24 19:32:16 -080032apply from: "build_dependencies.gradle"
Sergey Vasilinets164c38d2018-02-02 00:50:57 -080033apply plugin: "kotlin"
Jeff Gaston9cfb0a12019-11-06 17:50:14 -050034apply from: "kotlin-dsl-dependency.gradle"
Aurimas Liutikas9ab3b4c32017-04-19 09:33:27 -070035
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -050036allprojects {
37 repos.addMavenRepositories(repositories)
Jake Whartona0576c32018-07-27 13:09:42 -040038
Louis Pullen-Freilich834c8a92019-05-07 15:00:30 +010039 tasks.withType(KotlinCompile).configureEach {
40 kotlinOptions {
Aurimas Liutikas4c590262019-10-17 14:55:22 -070041 jvmTarget = "1.8"
Alan Viverette5baaf852020-06-04 16:10:19 +000042 freeCompilerArgs += [
43 "-Werror",
44 "-Xskip-runtime-version-check",
Jim Sprocha88c07a2020-06-25 13:00:03 -070045 "-Xskip-metadata-version-check",
Alan Viverette5baaf852020-06-04 16:10:19 +000046 // Allow `@OptIn` and `@UseExperimental`
47 "-Xopt-in=kotlin.RequiresOptIn"
48 ]
Louis Pullen-Freilich834c8a92019-05-07 15:00:30 +010049 }
50 }
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -050051}
Sergey Vasilinetsbb245e082017-10-11 00:16:04 -070052
Jeff Gaston1e27f972020-04-20 11:27:17 -040053configurations {
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 Gaston9093c152020-12-03 11:23:05 -050063 cacheableRuntimeOnly
Jeff Gaston1e27f972020-04-20 11:27:17 -040064}
65
Aurimas Liutikas9697da72016-12-22 15:50:42 -080066dependencies {
Jim Sproch9e38b4f2021-01-06 14:21:06 -080067 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 Vasilinets95f91db2020-01-13 20:21:29 +000073 // needed by inspection plugin
Jim Sproch9e38b4f2021-01-06 14:21:06 -080074 cacheableImplementation("com.google.protobuf:protobuf-gradle-plugin:0.8.13")
Sergey Vasilinets0256f572020-12-02 14:06:40 +000075 // TODO(aurimas): remove when b/174658825 is fixed
Jim Sproch9e38b4f2021-01-06 14:21:06 -080076 cacheableImplementation("org.anarres.jarjar:jarjar-gradle:1.0.1")
77 cacheableImplementation("com.github.jengelman.gradle.plugins:shadow:5.2.0")
Jeff Gaston1e27f972020-04-20 11:27:17 -040078 // dependencies that aren't used by buildSrc directly but that we resolve here so that the
79 // root project doesn't need to re-resolve them and their dependencies on every build
Jim Sproch9e38b4f2021-01-06 14:21:06 -080080 cacheableRuntimeOnly(build_libs.hilt_plugin)
Yigit Boyar23758df2020-12-16 18:47:29 -080081 // room kotlintestapp uses the ksp plugin but it does not publish a plugin marker yet
Jim Sproch9e38b4f2021-01-06 14:21:06 -080082 cacheableRuntimeOnly(build_libs.kotlin.ksp_gradle_plugin)
Jeff Gaston1e27f972020-04-20 11:27:17 -040083 // dependencies whose resolutions we don't need to cache
84 compileOnly(findGradleKotlinDsl()) // Only one file in this configuration, no need to cache it
Jim Sproch9e38b4f2021-01-06 14:21:06 -080085 implementation(project("jetpad-integration")) // Doesn't have a .pom, so not slow to load
Jeff Gaston1e27f972020-04-20 11:27:17 -040086}
87
Dustin Lam56130b22019-07-26 17:17:09 -070088apply plugin: "java-gradle-plugin"
89
90sourceSets {
91 main.java.srcDirs += "${supportRootFolder}/benchmark/gradle-plugin/src/main/kotlin"
92 main.resources.srcDirs += "${supportRootFolder}/benchmark/gradle-plugin/src/main/resources"
Sergey Vasilinets4e970562019-12-12 13:39:19 +000093
94 main.java.srcDirs += "${supportRootFolder}/inspection/inspection-gradle-plugin/src/main/kotlin"
95 main.resources.srcDirs += "${supportRootFolder}/inspection/inspection-gradle-plugin/src/main" +
96 "/resources"
Louis Pullen-Freilich5c6b11e2020-02-06 18:19:09 +000097
Louis Pullen-Freilichba7da082020-08-13 21:07:12 +010098 main.java.srcDirs += "${supportRootFolder}/compose/material/material/icons/generator/src/main" +
99 "/kotlin"
Dustin Lam56130b22019-07-26 17:17:09 -0700100}
101
102gradlePlugin {
103 plugins {
104 benchmark {
Jim Sproch9e38b4f2021-01-06 14:21:06 -0800105 id = "androidx.benchmark"
106 implementationClass = "androidx.benchmark.gradle.BenchmarkPlugin"
Dustin Lam56130b22019-07-26 17:17:09 -0700107 }
Sergey Vasilinets4e970562019-12-12 13:39:19 +0000108 inspection {
Jim Sproch9e38b4f2021-01-06 14:21:06 -0800109 id = "androidx.inspection"
110 implementationClass = "androidx.inspection.gradle.InspectionPlugin"
Sergey Vasilinets4e970562019-12-12 13:39:19 +0000111 }
Dustin Lam56130b22019-07-26 17:17:09 -0700112 }
Jeff Gaston9cfb0a12019-11-06 17:50:14 -0500113}
Jeff Gaston911812e2020-05-01 19:59:43 -0400114
115// Saves configuration into destFile
116// Each line of destFile will be the absolute filepath of one of the files in configuration
117def saveConfigurationResolution(configuration, destFile) {
118 def resolvedConfiguration = configuration.resolvedConfiguration
119 def files = resolvedConfiguration.files
120 def paths = files.collect { f -> f.toString() }
121 def serialized = paths.join("\n")
122 destFile.text = serialized
123}
124
125// Parses a file into a list of Dependency objects representing a ResolvedConfiguration
126def parseConfigurationResolution(savedFile) {
127 def savedText = savedFile.text
128 def filenames = savedText.split("\n")
129 def dependencies = filenames.collect { filename ->
130 project.dependencies.create(project.files(filename))
131 }
132 return dependencies
133}
134
135// Resolves a Configuration into a list of Dependency objects
136def resolveConfiguration(configuration) {
137 def resolvedName = configuration.name
138 def cacheDir = new File(project.buildDir, "/" + resolvedName)
139 def inputsFile = new File(cacheDir, "/deps")
140 def outputsFile = new File(cacheDir, "/result")
141
142 def inputText = fingerprintConfiguration(configuration)
143 if (!inputsFile.exists() || inputsFile.text != inputText) {
144 cacheDir.mkdirs()
145 saveConfigurationResolution(configuration, outputsFile)
146 inputsFile.text = inputText
147 }
148 def result = parseConfigurationResolution(outputsFile)
149 return result
150}
151
152// Computes a unique string from a Configuration based on its dependencies
153// This is used for up-to-date checks
154def fingerprintConfiguration(configuration) {
155 def dependencies = configuration.allDependencies
156 def dependencyTexts = dependencies.collect { dep -> dep.group + ":" + dep.name + ":" + dep.version }
157 return dependencyTexts.join("\n")
158}
159
160// Imports the contents of fromConf into toConf
161// Uses caching to often short-circuit the resolution of fromConf
162def loadConfigurationQuicklyInto(fromConf, toConf) {
163 def resolved = resolveConfiguration(fromConf)
164 resolved.each { dep ->
165 project.dependencies.add(toConf.name, dep)
166 }
167}
168
169loadConfigurationQuicklyInto(configurations.cacheableApi, configurations.api)
170loadConfigurationQuicklyInto(configurations.cacheableImplementation, configurations.implementation)
Jeff Gaston9093c152020-12-03 11:23:05 -0500171loadConfigurationQuicklyInto(configurations.cacheableRuntimeOnly, configurations.runtimeOnly)
Jeff Gaston52d044a2020-06-12 18:19:29 -0400172
173project.tasks.withType(Jar) { task ->
174 task.reproducibleFileOrder = true
175 task.preserveFileTimestamps = false
176}