-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathbuild.gradle
More file actions
268 lines (244 loc) · 11.5 KB
/
build.gradle
File metadata and controls
268 lines (244 loc) · 11.5 KB
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
// Top-level build file where you can add configuration options common to all sub-projects/modules.
import static de.fayard.refreshVersions.core.Versions.versionFor
import static com.gradle.develocity.agent.gradle.test.JUnitXmlDialect.*
import com.gradle.develocity.agent.gradle.test.ImportJUnitXmlReports
buildscript {
ext {
min_sdk = 26
target_sdk = 35
compile_sdk = 35
// Calculate lint_version (must always be gradle_plugin + 23)
def gradle_plugin_version = versionFor(project, Android.tools.build.gradlePlugin)
def components = gradle_plugin_version.split('\\.')
lint_version = gradle_plugin_version.replaceFirst(components[0], (components[0].toInteger() + 23).toString())
}
repositories {
google()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath(Android.tools.build.gradlePlugin)
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id 'com.squareup.anvil' apply false
id 'org.jetbrains.dokka'
id 'com.osacky.fulladle'
id 'org.jetbrains.kotlin.android' apply false
id 'com.google.devtools.ksp' apply false
id 'com.diffplug.spotless' apply false
}
// Proprietary DuckSans font swap. See https://app.asana.com/1/137249556945/project/1207908166761516/task/1213686706814504
def gprUser = findProperty("ducksans.gpr.user") ?: providers.environmentVariable("DUCKSANS_PACKAGE_AUTH_USER").getOrNull()
def gprKey = findProperty("ducksans.gpr.key") ?: providers.environmentVariable("DUCKSANS_PACKAGE_AUTH_TOKEN").getOrNull()
def hasGprCredentials = gprUser && gprKey
def useProprietaryFontProp = findProperty("useProprietaryFont")
ext.proprietaryFontAvailable = hasGprCredentials && useProprietaryFontProp?.toBoolean() != false
ext.proprietaryFontOptOut = useProprietaryFontProp?.toBoolean() == false
if (proprietaryFontAvailable) {
logger.lifecycle("DUCKSANS: Using proprietary font AAR from GitHub Packages")
} else if (proprietaryFontOptOut) {
logger.lifecycle("DUCKSANS: Using placeholder fallback fonts (opted out via -PuseProprietaryFont=false)")
} else {
logger.lifecycle("DUCKSANS: Using placeholder fallback fonts (no credentials found)")
}
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
if (rootProject.ext.proprietaryFontAvailable) {
maven {
url = uri("https://maven.pkg.github.com/duckduckgo/native-apps-ducksans")
credentials {
username = gprUser
password = gprKey
}
content {
includeGroup "com.duckduckgo"
}
}
}
}
configurations.all {
resolutionStrategy.force 'org.objenesis:objenesis:2.6'
}
}
subprojects {
if (project.name.endsWith("api")) {
apply plugin: 'org.jetbrains.dokka'
}
String[] allowAndroidTestsIn = ["app", "sync-lib", "httpsupgrade-impl", "pir-impl", "feature-toggles-impl"]
if (!allowAndroidTestsIn.contains(project.name)) {
project.projectDir.eachFile(groovy.io.FileType.DIRECTORIES) { File parent ->
if (parent.name == "src") {
parent.eachFile(groovy.io.FileType.DIRECTORIES) { child ->
if (child.name == "androidTest") {
throw new GradleException("Only the app module can have Android Tests. Perhaps you could use Robolectric?")
}
}
}
}
}
String[] allowStringsIn = ["app"]
if (!allowStringsIn.contains(project.name)) {
project.projectDir.eachDirRecurse { File parent ->
if (parent.name == "values") {
parent.eachFile(groovy.io.FileType.FILES) { child ->
if (child.name == "strings.xml") {
throw new GradleException("Duplicate strings.xml file found in $project. " +
"Only :app should contain the strings.xml file. " +
"Rename file to strings-<feature>.xml instead.")
}
}
}
}
}
def projectPath = path
configurations.configureEach {
if (name == "compileClasspath" || name.endsWith("CompileClasspath")) {
incoming.beforeResolve {
plugins.each { plugin ->
// API modules cannot use the anvil plugin
if (projectPath.endsWith("api")) {
if (plugin.toString().contains("com.squareup.anvil.plugin")) {
throw new GradleException("Invalid plugin $projectPath -> " +
"'api' modules can't use the anvil plugin")
}
}
if (!projectPath.endsWith(":app") && plugin.toString().toLowerCase().contains("kapt")) {
throw new GradleException("Invalid usage of kapt $projectPath -> " +
"Use ksp instead of kapt")
}
}
for (dependency in dependencies) {
// API modules cannot depend on dagger/anvil
if (projectPath.endsWith("api")
&& projectPath != ":feature-toggles-api"
&& projectPath != ":settings-api") {
def notAllowedDeps = ["anvil", "dagger"]
if (notAllowedDeps.contains(dependency.name)) {
throw new GradleException("Invalid dependency $projectPath -> " +
"'api' modules can't depend on dagger/anvil")
}
}
if (dependency instanceof ProjectDependency) {
def dependencyPath = dependency.dependencyProject.path
if (dependencyPath == projectPath) continue
// internal modules have to use internalImplementation
// when a non internal configuration is built (i.e. PlayDebug) no internal dependencies should be found
def internalExceptions = []
if (dependencyPath.endsWith('internal') && !internalExceptions.contains(dependencyPath) && !name.toLowerCase().contains("internal")) {
throw new GradleException("Invalid dependency $projectPath -> $dependencyPath. " +
"'internal' modules must use internalImplementation")
}
// internal modules can depend on impl
if (projectPath.endsWith('internal') && dependencyPath.endsWith('impl')) continue
if (!projectPath.endsWith(":app") && dependencyPath.endsWith("impl")) {
throw new GradleException("Invalid dependency $projectPath -> $dependencyPath. " +
"Only :app module can depend on 'impl' modules")
}
// API modules cannot depend on :di
if (projectPath.endsWith("api") && dependencyPath == ":di") {
throw new GradleException("Invalid dependency $projectPath -> $dependencyPath. " +
"'api' modules can't depend on the 'di' module")
}
// API modules can depend on :feature-toggles-api
if (projectPath.endsWith("api")
&& dependencyPath.endsWith("api")
&& dependencyPath != ":feature-toggles-api"
&& dependencyPath != ":navigation-api"
&& dependencyPath != ":js-messaging-api"
&& dependencyPath != ":browser-api"
) {
if (projectPath.endsWith(":feature-toggles-api") &&
(dependencyPath == ":experiments-api"
|| dependencyPath == ":feature-toggles-internal-api")
) {
// noop
} else {
throw new GradleException("Invalid dependency $projectPath -> $dependencyPath. " +
"'api' modules can't depend on other 'api' modules")
}
}
if (dependencyPath.endsWith(":app")) {
throw new GradleException("Invalid dependency $projectPath -> $dependencyPath. " +
"No other module can depend on ':app'")
}
}
}
}
}
resolutionStrategy.dependencySubstitution {
// Use Guava (which already bundles ListenableFuture) everywhere a bare listenablefuture is requested.
// Note: refreshVersions placeholders ("_") are not resolved in substitutions, so pin the version explicitly.
substitute(module("com.google.guava:listenablefuture"))
.using(module("com.google.guava:guava:33.4.0-android"))
.because("Use guava’s bundled ListenableFuture to avoid duplicate classes")
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
// Develocity test retry configuration to detect flaky tests
def isCI = System.getenv('CI') != null
subprojects {
tasks.withType(Test).configureEach {
useJUnitPlatform()
develocity.testRetry {
maxRetries = isCI ? 1 : 0
maxFailures = 5
failOnPassedAfterRetry = true
}
develocity.predictiveTestSelection {
enabled.set(System.getProperty("pts.enabled", "true").toBoolean())
}
}
}
fladle {
configs {
serviceAccountCredentials.set(project.layout.projectDirectory.file("flank.json"))
androidTests {
async.set(false)
flankVersion.set("21.+")
testShards.set(2)
useOrchestrator.set(false)
recordVideo.set(false)
testTargets.set([
"notAnnotation com.duckduckgo.espresso.PrivacyTest",
"notAnnotation com.duckduckgo.espresso.InternalPrivacyTest",
"notAnnotation com.duckduckgo.espresso.UserJourney",
])
devices.set([
["model": "MediumPhone.arm", "version": "30"],
["model": "Pixel2.arm", "version": "28"]
])
localResultsDir.set("fladleResults")
// retry once, if it succeeds it will be reported as a flaky test
flakyTestAttempts.set(1)
}
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
compilerOptions.freeCompilerArgs.addAll(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true",
)
}
afterEvaluate {
// Export Firebase Test Lab (Flank) tests to Develocity
tasks.matching { it.name.startsWith("execFlank") }.names.each {
ImportJUnitXmlReports.register(
tasks,
tasks.named(it),
ANDROID_FIREBASE
).configure {
reports.from(file("build/fladle/fladleResults/JUnitReport.xml"))
}
}
}
apply plugin: 'android-reporting'