Backed out changeset b622e2cb90ab (bug 1914850) for causing mochitest failures on...
[gecko.git] / mobile / android / focus-android / build.gradle
blobaf93f6e57bf8a3819ca0c949dd413944b799ed7c
1 import io.gitlab.arturbosch.detekt.Detekt
2 import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
3 import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
6 // Top-level build file where you can add configuration options common to all sub-projects/modules.
8 buildscript {
9     repositories {
10         gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
11             maven {
12                 url repository
13                 if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
14                     allowInsecureProtocol = true
15                 }
16             }
17         }
18     }
20     dependencies {
21         classpath ComponentsDependencies.tools_androidgradle
22         classpath ComponentsDependencies.tools_kotlingradle
23         classpath FocusDependencies.osslicenses_plugin
24         classpath "org.mozilla.telemetry:glean-gradle-plugin:${Versions.mozilla_glean}"
25         classpath "${ApplicationServicesConfig.groupId}:tooling-nimbus-gradle:${ApplicationServicesConfig.version}"
27         // NOTE: Do not place your application dependencies here; they belong
28         // in the individual module build.gradle files
29     }
31     // Variables in plugins {} aren't directly supported. Hack around it by setting an
32     // intermediate variable which can pull from FocusDependenciesPlugin.kt and be used later.
33     ext {
34         detekt_plugin = Versions.detekt
35         python_envs_plugin = Versions.python_envs_plugin
36         ksp_plugin = Versions.ksp_plugin
37     }
40 plugins {
41     id "io.gitlab.arturbosch.detekt" version "$detekt_plugin"
42     id("com.google.devtools.ksp").version("$ksp_plugin")
45 detekt {
46     input = files("$projectDir/app")
47     config = files("$projectDir/quality/detekt.yml")
48     baseline = file("$projectDir/quality/detekt-baseline.xml")
50     reports {
51         html {
52             enabled = true
53             destination = file("$projectDir/build/reports/detekt.html")
54         }
55         xml {
56             enabled = false
57         }
58         txt {
59             enabled = false
60         }
61     }
64 tasks.withType(Detekt).configureEach() {
65     autoCorrect = true
67     exclude "**/test/**"
68     exclude "**/androidTest/**"
69     exclude "**/build/**"
70     exclude "**/resources/**"
71     exclude "**/tmp/**"
74 // Apply same path exclusions as for the main task
75 tasks.withType(DetektCreateBaselineTask).configureEach() {
76     exclude "**/test/**"
77     exclude "**/androidTest/**"
78     exclude "**/build/**"
79     exclude "**/resources/**"
80     exclude "**/tmp/**"
83 allprojects {
84     repositories {
85         gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
86             maven {
87                 url repository
88                 if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
89                     allowInsecureProtocol = true
90                 }
91             }
92         }
94         maven {
95             url "${gradle.mozconfig.topobjdir}/gradle/maven"
96         }
97     }
100 subprojects {
101     afterEvaluate {
102         kotlin {
103             jvmToolchain(config.jvmTargetCompatibility)
104         }
105     }
107     tasks.withType(KotlinCompile).configureEach { task ->
108         // Translate Kotlin messages like "w: ..." and "e: ..." into
109         // "...: warning: ..." and "...: error: ...", to make Treeherder understand.
110         def listener = {
112             if (it.startsWith("e: warnings found")) {
113                 return
114             }
116             if (it.startsWith('w: ') || it.startsWith('e: ')) {
117                 def matches = (it =~ /([ew]): (.+):(\d+):(\d+) (.*)/)
118                 if (!matches) {
119                     logger.quiet "kotlinc message format has changed!"
120                     if (it.startsWith('w: ')) {
121                         // For warnings, don't continue because we don't want to throw an
122                         // exception. For errors, we want the exception so that the new error
123                         // message format gets translated properly.
124                         return
125                     }
126                 }
127                 def (_, type, file, line, column, message) = matches[0]
128                 type = (type == 'w') ? 'warning' : 'error'
129                 // Use logger.lifecycle, which does not go through stderr again.
130                 logger.lifecycle "$file:$line:$column: $type: $message"
131             }
132         } as StandardOutputListener
134         doFirst {
135             logging.addStandardErrorListener(listener)
136         }
137         doLast {
138             logging.removeStandardErrorListener(listener)
139         }
140     }
143 tasks.register('clean', Delete) {
144     delete rootProject.layout.buildDirectory
148 configurations {
149     ktlint
152 dependencies {
153     ktlint("com.pinterest:ktlint:${Versions.ktlint}") {
154         attributes {
155             attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
156         }
157     }
160 tasks.register('ktlint', JavaExec) {
161     description = "Check Kotlin code style."
162     classpath = configurations.ktlint
163     mainClass.set("com.pinterest.ktlint.Main")
164     args "app/**/*.kt", "!**/build/**/*.kt", "buildSrc/**/*.kt", "--reporter=json,output=build/reports/ktlint/ktlint.json"
168 tasks.register('ktlintFormat', JavaExec) {
169     description = "Fix Kotlin code style deviations."
170     classpath = configurations.ktlint
171     mainClass.set("com.pinterest.ktlint.Main")
172     args "-F", "app/**/*.kt", "!**/build/**/*.kt", "buildSrc/**/*.kt"
173     jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
176 tasks.register("listRepositories") {
177     doLast {
178         println "Repositories:"
179         project.repositories.each { println "Name: " + it.name + "; url: " + it.url }
180    }