forked from google/horologist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
296 lines (257 loc) · 10.9 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import com.android.build.gradle.LibraryExtension
import com.vanniktech.maven.publish.SonatypeHost
import java.net.URL
import java.util.Properties
/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath(libs.android.tools.build.gradle)
classpath(libs.kotlin.gradlePlugin)
classpath(libs.gradleMavenPublishPlugin)
classpath(libs.dokka)
classpath(libs.dagger.hiltandroidplugin)
}
}
plugins {
alias(libs.plugins.spotless)
alias(libs.plugins.kotlinGradle) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.protobuf) apply false
alias(libs.plugins.gradleMavenPublishPlugin)
alias(libs.plugins.metalavaGradle) apply false
alias(libs.plugins.dependencyAnalysis)
alias(libs.plugins.roborazzi) apply false
alias(libs.plugins.kotlinx.serialization) apply false
}
apply(plugin = "org.jetbrains.dokka")
tasks.withType<org.jetbrains.dokka.gradle.DokkaMultiModuleTask>().configureEach {
outputDirectory.set(rootProject.file("docs/api"))
failOnWarning.set(true)
}
allprojects {
repositories {
google()
mavenCentral()
val composeSnapshot = rootProject.libs.versions.composesnapshot.get()
if (composeSnapshot.length > 1) {
maven(url = uri("https://androidx.dev/snapshots/builds/$composeSnapshot/artifacts/repository/"))
}
maven {
url = uri("https://jitpack.io")
content {
includeGroup("com.github.QuickBirdEng.kotlin-snapshot-testing")
}
}
}
plugins.withId("com.vanniktech.maven.publish") {
mavenPublishing {
publishToMavenCentral(SonatypeHost("https://google.oss.sonatype.org"))
}
}
}
subprojects {
apply(plugin = "com.diffplug.spotless")
if (childProjects.isEmpty()) {
spotless {
kotlin {
target("**/*.kt")
ktlint(libs.versions.ktlint.get())
.setEditorConfigPath(rootProject.file("quality/ktlint/.editorconfig"))
licenseHeaderFile(rootProject.file("spotless/copyright.txt"))
}
kotlinGradle {
target("**/*.gradle.kts")
ktlint(libs.versions.ktlint.get())
.setEditorConfigPath(rootProject.file("quality/ktlint/.editorconfig"))
licenseHeaderFile(
rootProject.file("spotless/copyright.txt"),
"(buildscript|apply|import|plugins)"
)
}
}
}
configurations.configureEach {
resolutionStrategy.eachDependency {
// Make sure that we're using the Android version of Guava
if ([email protected]("android", ignoreCase = true)
&& requested.group == "com.google.guava"
&& requested.module.name == "guava"
&& requested.version?.contains("jre") == true) {
requested.version?.replace(
"jre",
"android"
)?.let { useVersion(it) }
}
if (requested.group.startsWith("androidx.compose.") && requested.version == "1.7.0-alpha08") {
useVersion("1.7.0-alpha07")
}
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
if (System.getenv("CI") == "true") {
// Treat all Kotlin warnings as errors
allWarningsAsErrors = true
}
// Set JVM target to 1.8
jvmTarget = "11"
freeCompilerArgs = freeCompilerArgs + listOf(
// Allow use of @OptIn
"-opt-in=kotlin.RequiresOptIn",
// Enable default methods in interfaces
"-Xjvm-default=all"
)
}
}
// Read in the signing.properties file if it is exists
val signingPropsFile = rootProject.file("release/signing.properties")
if (signingPropsFile.exists()) {
val localProperties = Properties()
signingPropsFile.inputStream().use { istream -> localProperties.load(istream) }
localProperties.forEach { prop ->
project.extra[prop.key as String] = prop.value
}
}
// Must be afterEvaluate or else com.vanniktech.maven.publish will overwrite our
// dokka and version configuration.
afterEvaluate {
if (tasks.findByName("dokkaHtmlPartial") == null) {
// If dokka isn't enabled on this module, skip
return@afterEvaluate
}
tasks.named<org.jetbrains.dokka.gradle.DokkaTaskPartial>("dokkaHtmlPartial") {
dokkaSourceSets.configureEach {
reportUndocumented.set(true)
skipEmptyPackages.set(true)
skipDeprecated.set(true)
jdkVersion.set(8)
// Add Android SDK packages
noAndroidSdkLink.set(false)
// Add samples from :sample module
samples.from(
rootProject.file("auth/sample/src/main/java/"),
rootProject.file("auth/sample/wear/src/main/java/"),
rootProject.file("media/sample/src/main/java/"),
rootProject.file("sample/src/main/java/"),
)
// AndroidX + Compose docs
externalDocumentationLink {
url.set(URL("https://developer.android.com/reference/"))
packageListUrl.set(URL("https://developer.android.com/reference/androidx/package-list"))
}
externalDocumentationLink {
url.set(URL("https://developer.android.com/reference/kotlin/"))
packageListUrl.set(URL("https://developer.android.com/reference/kotlin/androidx/package-list"))
}
sourceLink {
localDirectory.set(project.file("src/main/java"))
// URL showing where the source code can be accessed through the web browser
remoteUrl.set(URL("https://github.com/google/horologist/blob/main/${project.name}/src/main/java"))
// Suffix which is used to append the line number to the URL. Use #L for GitHub
remoteLineSuffix.set("#L")
}
perPackageOption {
matchingRegex.set("com.google.android.horologist.auth.sample.shared.*")
suppress.set(true)
}
// Remove composable previews from docs
suppressedFiles.from(file("src/debug/java"))
}
}
if (plugins.hasPlugin("com.android.library")) {
configure<LibraryExtension> {
lint {
// Remove once fixed: https://issuetracker.google.com/196420849
disable.add("ExpiringTargetSdkVersion")
}
}
}
val buildDir = project.layout.buildDirectory
val outputDirectory =
buildDir.dir("generated/sources/generateVersionFile")
val generateVersionFile = tasks.register("generateVersionFile") {
doLast {
val versionName = project.properties["VERSION_NAME"] as String
val manifestDir = outputDirectory.get().dir("META-INF")
manifestDir.asFile.mkdirs()
val name = if (project.parent?.name == "horologist")
project.name
else
project.parent?.name + project.name
manifestDir.file(
"com.google.android.horologist_$name.version"
).asFile.writeText("${versionName}\n")
}
}
afterEvaluate {
val processResources = tasks.findByName("processResources")
if (processResources != null) {
processResources.dependsOn(generateVersionFile)
val sourceSets = extensions.getByType(SourceSetContainer::class)
val resources = sourceSets.findByName("main")?.resources
resources?.srcDir(outputDirectory)
}
val isLibrary = plugins.hasPlugin("com.android.library")
if (isLibrary) {
val library = extensions.getByType(LibraryExtension::class)
val resources = library.sourceSets.findByName("main")?.resources!!
resources.srcDir(outputDirectory)
if (resources.includes.isNotEmpty()) {
resources.include("META-INF/*.version")
}
library.libraryVariants.all {
processJavaResourcesProvider.get().dependsOn(generateVersionFile)
}
}
}
}
afterEvaluate {
var version: String? = null
val composeSnapshot = libs.versions.composesnapshot.get()
if (composeSnapshot.length > 1) {
// We're depending on a Jetpack Compose snapshot, update the library version name
// to indicate it's from a Compose snapshot
val versionName = project.properties.get("VERSION_NAME") as String
if (versionName.contains("SNAPSHOT")) {
version = versionName.replace("-SNAPSHOT", ".compose-${composeSnapshot}-SNAPSHOT")
}
}
if (version?.endsWith("SNAPSHOT") == false) {
// If we're not a SNAPSHOT library version, we fail the build if we're relying on
// any snapshot dependencies
configurations.configureEach {
dependencies.configureEach {
if (this is ProjectDependency) {
// We don't care about internal project dependencies
return@configureEach
}
// val depVersion = dependency.version
// TODO reenable https://github.com/google/horologist/issues/34
// if (depVersion != null && depVersion.endsWith("SNAPSHOT")) {
// throw IllegalArgumentException(
// "Using SNAPSHOT dependency with non-SNAPSHOT library version: $dependency"
// )
// }
}
}
}
}
}