blob: 2bab62e501e7c7c36a295a4dad3a8316dcef6140 [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")
Chris Craik3a06f1e2021-04-22 10:47:29 -070075 cacheableImplementation(build_libs.wire_plugin)
Sergey Vasilinets0256f572020-12-02 14:06:40 +000076 // TODO(aurimas): remove when b/174658825 is fixed
Jim Sproch9e38b4f2021-01-06 14:21:06 -080077 cacheableImplementation("org.anarres.jarjar:jarjar-gradle:1.0.1")
Aurimas Liutikasc1a597b2021-04-20 11:05:38 -070078 cacheableImplementation(build_libs.shadow)
Jeff Gaston1e27f972020-04-20 11:27:17 -040079 // 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 Sproch9e38b4f2021-01-06 14:21:06 -080081 cacheableRuntimeOnly(build_libs.hilt_plugin)
Yigit Boyar23758df2020-12-16 18:47:29 -080082 // room kotlintestapp uses the ksp plugin but it does not publish a plugin marker yet
Jim Sproch9e38b4f2021-01-06 14:21:06 -080083 cacheableRuntimeOnly(build_libs.kotlin.ksp_gradle_plugin)
Jeff Gaston1e27f972020-04-20 11:27:17 -040084 // dependencies whose resolutions we don't need to cache
85 compileOnly(findGradleKotlinDsl()) // Only one file in this configuration, no need to cache it
Jim Sproch9e38b4f2021-01-06 14:21:06 -080086 implementation(project("jetpad-integration")) // Doesn't have a .pom, so not slow to load
Jeff Gaston1e27f972020-04-20 11:27:17 -040087}
88
Dustin Lam56130b22019-07-26 17:17:09 -070089apply plugin: "java-gradle-plugin"
90
91sourceSets {
92 main.java.srcDirs += "${supportRootFolder}/benchmark/gradle-plugin/src/main/kotlin"
93 main.resources.srcDirs += "${supportRootFolder}/benchmark/gradle-plugin/src/main/resources"
Sergey Vasilinets4e970562019-12-12 13:39:19 +000094
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-Freilich5c6b11e2020-02-06 18:19:09 +000098
Louis Pullen-Freilichba7da082020-08-13 21:07:12 +010099 main.java.srcDirs += "${supportRootFolder}/compose/material/material/icons/generator/src/main" +
100 "/kotlin"
Dustin Lam56130b22019-07-26 17:17:09 -0700101}
102
103gradlePlugin {
104 plugins {
105 benchmark {
Jim Sproch9e38b4f2021-01-06 14:21:06 -0800106 id = "androidx.benchmark"
107 implementationClass = "androidx.benchmark.gradle.BenchmarkPlugin"
Dustin Lam56130b22019-07-26 17:17:09 -0700108 }
Sergey Vasilinets4e970562019-12-12 13:39:19 +0000109 inspection {
Jim Sproch9e38b4f2021-01-06 14:21:06 -0800110 id = "androidx.inspection"
111 implementationClass = "androidx.inspection.gradle.InspectionPlugin"
Sergey Vasilinets4e970562019-12-12 13:39:19 +0000112 }
Dustin Lam56130b22019-07-26 17:17:09 -0700113 }
Jeff Gaston9cfb0a12019-11-06 17:50:14 -0500114}
Jeff Gaston911812e2020-05-01 19:59:43 -0400115
116// Saves configuration into destFile
117// Each line of destFile will be the absolute filepath of one of the files in configuration
118def 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
127def 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
137def 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
155def 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
163def loadConfigurationQuicklyInto(fromConf, toConf) {
164 def resolved = resolveConfiguration(fromConf)
165 resolved.each { dep ->
166 project.dependencies.add(toConf.name, dep)
167 }
168}
169
170loadConfigurationQuicklyInto(configurations.cacheableApi, configurations.api)
171loadConfigurationQuicklyInto(configurations.cacheableImplementation, configurations.implementation)
Jeff Gaston9093c152020-12-03 11:23:05 -0500172loadConfigurationQuicklyInto(configurations.cacheableRuntimeOnly, configurations.runtimeOnly)
Jeff Gaston52d044a2020-06-12 18:19:29 -0400173
174project.tasks.withType(Jar) { task ->
175 task.reproducibleFileOrder = true
176 task.preserveFileTimestamps = false
177}