File: build.gradle

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (419 lines) | stat: -rw-r--r-- 15,493 bytes parent folder | download
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
// Top-level build file where you can add configuration options common to all sub-projects/modules.

import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
import org.gradle.internal.logging.text.StyledTextOutput.Style
import org.gradle.internal.logging.text.StyledTextOutputFactory
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import static org.gradle.api.tasks.testing.TestResult.ResultType

buildscript {
    repositories {
        gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
            maven {
                url = repository
                if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
                    allowInsecureProtocol = true
                }
            }
        }
    }

    dependencies {
        classpath libs.android.gradle.plugin
    }
}

plugins {
    alias(libs.plugins.detekt)
    alias(libs.plugins.kotlin.android) apply false
    alias(libs.plugins.kotlin.compose) apply false
    alias(libs.plugins.ksp)
}

allprojects {
    repositories {
        gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
            maven {
                url = repository
                if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
                    allowInsecureProtocol = true
                }
            }
        }

        maven {
            url = "${gradle.mozconfig.topobjdir}/gradle/maven"
        }
    }

    ext {
        gleanVersion = libs.versions.glean.get()
    }

    // Enable Kotlin warnings as errors for all modules
    tasks.withType(KotlinCompile).configureEach {
        compilerOptions.allWarningsAsErrors = true
    }

    if (gradle.mozconfig.substs.DOWNLOAD_ALL_GRADLE_DEPENDENCIES) {
        // Work around https://github.com/google/ksp/issues/1964 by explicitly
        // declaring dependencies that are dynamically added during Gradle task
        // execution.
        pluginManager.withPlugin('com.google.devtools.ksp') {
            project.configurations {
                kspDependencies
            }

            project.dependencies {
                kspDependencies libs.ksp.symbol.processing.aa
                kspDependencies libs.ksp.symbol.processing.aa.embeddable
                kspDependencies libs.ksp.symbol.processing.api
                kspDependencies libs.ksp.symbol.processing.common.deps
            }
        }
    }
}

subprojects {
    apply plugin: 'jacoco'

    // Prevent some dependencies used by Fenix/Focus from being used in AC.
    project.configurations.all {
        exclude group: 'com.adjust.sdk', module: 'adjust-android'
        exclude group: 'io.mockk', module: 'mockk'
    }

    project.configurations.configureEach {
        // Dependencies can't depend on a different major version of Glean than A-C itself.
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'org.mozilla.telemetry'
                    && details.requested.name.contains('glean') ) {
                def requested = details.requested.version.tokenize(".")
                def defined = project.ext.gleanVersion.tokenize(".")
                // Check the major version
                if (requested[0] != defined[0]) {
                    throw new AssertionError("Cannot resolve to a single Glean version. Requested: ${details.requested.version}, A-C uses: ${project.ext.gleanVersion}")
                } else {
                    // Enforce that all (transitive) dependencies are using the defined Glean version
                    details.useVersion project.ext.gleanVersion
                }
            }
        }

        resolutionStrategy.capabilitiesResolution.withCapability("org.mozilla.telemetry:glean-native") {
            def toBeSelected = candidates.find { it.id instanceof ModuleComponentIdentifier && it.id.module.contains('geckoview') }
            if (toBeSelected != null) {
                select(toBeSelected)
            }
            because 'use GeckoView Glean instead of standalone Glean'
        }
    }

    if (gradle.hasProperty('localProperties.dependencySubstitutions.geckoviewTopsrcdir')) {
        if (gradle.hasProperty('localProperties.dependencySubstitutions.geckoviewTopobjdir')) {
            ext.topobjdir = gradle."localProperties.dependencySubstitutions.geckoviewTopobjdir"
        }
        ext.topsrcdir = gradle."localProperties.dependencySubstitutions.geckoviewTopsrcdir"
        apply from: "${topsrcdir}/substitute-local-geckoview.gradle"
    }

    afterEvaluate {
        if (it.hasProperty('android')) {
            // Format test output
            tasks.matching {it instanceof Test}.configureEach() {
                systemProperty "robolectric.logging", "stdout"
                systemProperty "logging.test-mode", "true"
                systemProperty "javax.net.ssl.trustStoreType", "JKS"

                testLogging.events = []

                beforeSuite { descriptor ->
                    if (descriptor.getClassName() != null) {
                        println("\nSUITE: " + descriptor.getClassName())
                    }
                }

                beforeTest { descriptor ->
                    println("  TEST: " + descriptor.getName())
                }

                onOutput { descriptor, event ->
                    it.logger.lifecycle("    " + event.message.trim())
                }

                afterTest { descriptor, result ->
                    switch (result.getResultType()) {
                        case ResultType.SUCCESS:
                            println("  SUCCESS")
                            break

                        case ResultType.FAILURE:
                            def testId = descriptor.getClassName() + "." + descriptor.getName()
                            println("  TEST-UNEXPECTED-FAIL | " + testId + " | " + result.getException())
                            break

                        case ResultType.SKIPPED:
                            println("  SKIPPED")
                            break
                    }
                    it.logger.lifecycle("")
                }
            }

            dependencies {
                lintChecks project(':components:tooling-lint')
            }

            kotlin {
                jvmToolchain(config.jvmTargetCompatibility)
            }

            android {
                // We can't have one baseline file at the root of android-components because
                // this is not a project module and we would have to coordinate every module to
                // merge baselines.
                lint {
                    baseline = file("${projectDir}/lint-baseline.xml")
                }

                buildToolsVersion gradle.mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION

                testOptions {
                    testCoverage {
                        jacocoVersion = libs.versions.jacoco.get()
                    }
                    unitTests {
                        includeAndroidResources = true
                    }
                }

                packaging {
                    resources {
                        excludes += ['META-INF/LICENSE.md', 'META-INF/LICENSE-notice.md']
                    }
                }

                androidResources {
                    ignoreAssetsPattern = "manifest.template.json"
                }
            }

            if (project.name != "support-test") {
                android.buildTypes.all { buildType ->
                    tasks.withType(Test).configureEach() {
                        jacoco {
                            includeNoLocationClasses = true
                            excludes = ['jdk.internal.*']
                        }

                        finalizedBy { "jacoco${buildType.name.capitalize()}TestReport" }
                    }

                    tasks.register("jacoco${buildType.name.capitalize()}TestReport", JacocoReport) {
                        reports {
                            xml.required = true
                            html.required = true
                        }

                        def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*',
                                          '**/*Test*.*', 'android/**/*.*', '**/*$[0-9].*']
                        def kotlinDebugTree = fileTree(dir: "$project.layout.buildDirectory/tmp/kotlin-classes/${buildType.name}", excludes: fileFilter)
                        def javaDebugTree = fileTree(dir: "$project.layout.buildDirectory/intermediates/classes/${buildType.name}", excludes: fileFilter)
                        def mainSrc = "$project.projectDir/src/main/java"

                        sourceDirectories.setFrom(files([mainSrc]))
                        classDirectories.setFrom(files([kotlinDebugTree, javaDebugTree]))
                        getExecutionData().setFrom(fileTree(project.layout.buildDirectory).include([
                                "jacoco/test${buildType.name.capitalize()}UnitTest.exec"
                        ]))
                    }
                }

                android {
                    buildTypes {
                        debug {
                            // Enable test coverage when fetching dependencies: it's an easy way to
                            // ensure we fetch the Jacoco agent dependency `org.jacoco.agent`, which
                            // resolves to `org.jacoco.agent-$VERSION-runtime.jar`.
                            testCoverageEnabled = project.hasProperty("coverage") || gradle.mozconfig.substs.DOWNLOAD_ALL_GRADLE_DEPENDENCIES
                        }
                    }
                }
            }
        }
    }

    tasks.withType(KotlinCompile).configureEach {
        // Translate Kotlin messages like "w: ..." and "e: ..." into
        // "...: warning: ..." and "...: error: ...", to make Treeherder understand.
        def listener = {
            if (it.startsWith("e: warnings found")) {
                return
            }

            if (it.startsWith('w: ') || it.startsWith('e: ')) {
                def matches = (it =~ /([ew]): (.+):(\d+):(\d+) (.*)/)
                if (!matches) {
                    logger.quiet "kotlinc message format has changed!"
                    if (it.startsWith('w: ')) {
                        // For warnings, don't continue because we don't want to throw an
                        // exception. For errors, we want the exception so that the new error
                        // message format gets translated properly.
                        return
                    }
                }
                def (_, type, file, line, column, message) = matches[0]
                type = (type == 'w') ? 'warning' : 'error'
                // Use logger.lifecycle, which does not go through stderr again.
                logger.lifecycle "$file:$line:$column: $type: $message"
            }
        } as StandardOutputListener

        doFirst {
            logging.addStandardErrorListener(listener)
        }
        doLast {
            logging.removeStandardErrorListener(listener)
        }
    }
}

if (findProject(":geckoview") == null) {
    // Avoid adding this task if it already exists in a different root project.
    tasks.register("clean", Delete) {
        delete rootProject.layout.buildDirectory
    }
}

detekt {
    input = files("$projectDir/components", "$projectDir/buildSrc", "$projectDir/samples")
    config = files("$projectDir/config/detekt.yml")
    baseline = file("$projectDir/config/detekt-baseline.xml")

    reports {
        html {
            enabled = true
            destination = file("$projectDir/build/reports/detekt.html")
        }
        xml {
            enabled = false
        }
        txt {
            enabled = false
        }
    }
}

tasks.named("detekt").configure {
    reports {
        custom {
            reportId = "suppression-count"
            outputLocation.set(file("$projectDir/build/reports/suppressions.txt"))
        }
    }
}

tasks.withType(Detekt).configureEach() {
    // Custom detekt rules should be built before.
    // See https://detekt.dev/docs/introduction/extensions#pitfalls
    dependsOn(":components:tooling-detekt:assemble")

    autoCorrect = true

    exclude "**/build.gradle.kts"
    exclude "**/build/**"
    exclude "**/docs/**"
    exclude "**/resources/**"
    exclude "**/src/androidTest/**"
    exclude "**/src/iosTest/**"
    exclude "**/src/main/assets/extensions/**"
    exclude "**/src/test/**"
    exclude "**/test/src/**"
    exclude "**/tmp/**"
    exclude "**/tooling/fetch-tests/**"
}

// Apply same path exclusions as for the main task
tasks.withType(DetektCreateBaselineTask).configureEach() {
    dependsOn(":components:browser-icons:updateBuiltInExtensionVersion")
    dependsOn(":components:feature-accounts:updateBuiltInExtensionVersion")
    dependsOn(":components:feature-readerview:updateBuiltInExtensionVersion")
    dependsOn(":components:feature-search:updateAdsExtensionVersion")
    dependsOn(":components:feature-search:updateCookiesExtensionVersion")
    dependsOn(":components:samples-browser:updateBorderifyExtensionVersion")
    dependsOn(":components:samples-browser:updateTestExtensionVersion")
    dependsOn(":components:samples-compose-browser:updateBorderifyExtensionVersion")
    dependsOn(":components:samples-compose-browser:updateTestExtensionVersion")
    dependsOn(":components:tooling-detekt:assemble")

    exclude "**/build.gradle.kts"
    exclude "**/build/**"
    exclude "**/docs/**"
    exclude "**/resources/**"
    exclude "**/src/androidTest/**"
    exclude "**/src/iosTest/**"
    exclude "**/src/main/assets/extensions/**"
    exclude "**/src/test/**"
    exclude "**/test/src/**"
    exclude "**/tmp/**"
    exclude "**/tooling/fetch-tests/**"
}

configurations {
    ktlint

    detektDependencies
}

dependencies {
    ktlint(libs.ktlint) {
        attributes {
            attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
        }
    }
    detektPlugins project(":components:tooling-detekt")
    detekt libs.detekt.cli

    detektDependencies libs.detekt.cli
}

tasks.register("ktlint", JavaExec) {
    group = "verification"
    description = "Check Kotlin code style."
    classpath = configurations.ktlint
    mainClass.set("com.pinterest.ktlint.Main")
    args "components/**/*.kt"
    args "samples/**/*.kt"
    args "!**/build/**/*.kt"
    args "buildSrc/**/*.kt"
    args "--reporter=json,output=build/reports/ktlint/ktlint.json"
    args "--reporter=plain"
}

tasks.register("ktlintFormat", JavaExec) {
    group = "formatting"
    description = "Fix Kotlin code style deviations."
    classpath = configurations.ktlint
    mainClass.set("com.pinterest.ktlint.Main")
    args "-F"
    args "components/**/*.kt"
    args "samples/**/*.kt"
    args "!**/build/**/*.kt"
    args "buildSrc/**/*.kt"
    args "--reporter=json,output=build/reports/ktlint/ktlintFormat.json"
    args "--reporter=plain"
    jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
}

tasks.register("listRepositories") {
    def reposData = project.provider {
        project.repositories.collect { repo ->
            [name: repo.name, url: repo.url.toString()]
        }
    }
    doLast {
        println "Repositories:"
        reposData.get().each { println "Name: " + it.name + "; url: " + it.url }
    }
}