Bug 1891342 - Part 2: Update iconAccentViolet color to Violet70 r=android-reviewers...
[gecko.git] / mobile / android / fenix / build.gradle
blob097d30e9371cbcb241c799444d0c7d4f48a6c452
1 // Top-level build file where you can add configuration options common to all sub-projects/modules.
3 import io.gitlab.arturbosch.detekt.Detekt
4 import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
5 import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
6 import java.nio.file.Files
7 import java.nio.file.Paths
8 import java.nio.file.StandardCopyOption
10 buildscript {
11     // This logic is duplicated in the allprojects block: I don't know how to fix that.
12     repositories {
13         gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
14             maven {
15                 url repository
16                 if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
17                     allowInsecureProtocol = true
18                 }
19             }
20         }
21     }
23     dependencies {
24         classpath ComponentsDependencies.tools_androidgradle
25         classpath ComponentsDependencies.tools_kotlingradle
26         classpath FenixDependencies.tools_benchmarkgradle
27         classpath ComponentsDependencies.androidx_safeargs
28         classpath FenixDependencies.osslicenses_plugin
29         classpath "org.mozilla.telemetry:glean-gradle-plugin:${Versions.mozilla_glean}"
30         classpath "${ApplicationServicesConfig.groupId}:tooling-nimbus-gradle:${ApplicationServicesConfig.version}"
32         // NOTE: Do not place your application dependencies here; they belong
33         // in the individual module build.gradle files
34     }
36     // Variables in plugins {} aren't directly supported. Hack around it by setting an
37     // intermediate variable which can pull from FenixDependenciesPlugin.kt and be used later.
38     ext {
39         detekt_plugin = Versions.detekt
40         ksp_plugin = Versions.ksp_plugin
41         protobuf_plugin = FenixVersions.protobuf_plugin
42         python_envs_plugin = Versions.python_envs_plugin
43     }
46 plugins {
47     id("io.gitlab.arturbosch.detekt").version("$detekt_plugin")
48     id("com.google.devtools.ksp").version("$ksp_plugin")
51 allprojects {
52     // This logic is duplicated in the buildscript block: I don't know how to fix that.
53     repositories {
54         gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
55             maven {
56                 url repository
57                 if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
58                     allowInsecureProtocol = true
59                 }
60             }
61         }
63         maven {
64             url "${gradle.mozconfig.topobjdir}/gradle/maven"
65         }
66     }
68     tasks.withType(KotlinCompile).configureEach {
69         kotlinOptions.allWarningsAsErrors = true
70         kotlinOptions.freeCompilerArgs += [
71                 "-opt-in=kotlin.RequiresOptIn", "-Xjvm-default=all-compatibility"
72         ]
73     }
76 subprojects {
77     afterEvaluate {
78         kotlin {
79             jvmToolchain(config.jvmTargetCompatibility)
80         }
81     }
83     tasks.withType(KotlinCompile).configureEach { task ->
84         // Translate Kotlin messages like "w: ..." and "e: ..." into
85         // "...: warning: ..." and "...: error: ...", to make Treeherder understand.
86         def listener = {
88             if (it.startsWith("e: warnings found")) {
89                 return
90             }
92             if (it.startsWith('w: ') || it.startsWith('e: ')) {
93                 def matches = (it =~ /([ew]): (.+):(\d+):(\d+) (.*)/)
94                 if (!matches) {
95                     logger.quiet "kotlinc message format has changed!"
96                     if (it.startsWith('w: ')) {
97                         // For warnings, don't continue because we don't want to throw an
98                         // exception. For errors, we want the exception so that the new error
99                         // message format gets translated properly.
100                         return
101                     }
102                 }
103                 def (_, type, file, line, column, message) = matches[0]
104                 type = (type == 'w') ? 'warning' : 'error'
105                 // Use logger.lifecycle, which does not go through stderr again.
106                 logger.lifecycle "$file:$line:$column: $type: $message"
107             }
108         } as StandardOutputListener
110         doFirst {
111             logging.addStandardErrorListener(listener)
112         }
113         doLast {
114             logging.removeStandardErrorListener(listener)
115         }
116     }
119 tasks.register('clean', Delete) {
120     delete rootProject.layout.buildDirectory
123 detekt {
124     input = files("$projectDir/app/src")
125     config = files("$projectDir/config/detekt.yml")
127     reports {
128         html {
129             enabled = true
130             destination = file("$projectDir/build/reports/detekt.html")
131         }
132         xml {
133             enabled = false
134         }
135         txt {
136             enabled = false
137         }
138     }
141 tasks.withType(Detekt).configureEach() {
142     autoCorrect = true
144     exclude "**/test/**"
145     exclude "**/androidTest/**"
146     exclude "**/build/**"
147     exclude "**/resources/**"
148     exclude "**/tmp/**"
151 // Apply same path exclusions as for the main task
152 tasks.withType(DetektCreateBaselineTask).configureEach() {
153     exclude "**/test/**"
154     exclude "**/androidTest/**"
155     exclude "**/build/**"
156     exclude "**/resources/**"
157     exclude "**/tmp/**"
160 configurations {
161     ktlint
164 dependencies {
165     ktlint("com.pinterest:ktlint:${Versions.ktlint}") {
166         attributes {
167             attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
168         }
169     }
171     detekt project(":mozilla-detekt-rules")
172     detekt "io.gitlab.arturbosch.detekt:detekt-cli:${Versions.detekt}"
175 tasks.register('ktlint', JavaExec) {
176     group = "verification"
177     description = "Check Kotlin code style."
178     classpath = configurations.ktlint
179     mainClass.set("com.pinterest.ktlint.Main")
180     args "app/src/**/*.kt", "!**/build/**/*.kt", "--baseline=ktlint-baseline.xml"
183 tasks.register('ktlintFormat', JavaExec) {
184     description = "Fix Kotlin code style deviations."
185     classpath = configurations.ktlint
186     mainClass.set("com.pinterest.ktlint.Main")
187     args "-F", "app/src/**/*.kt", "!**/build/**/*.kt", "--baseline=ktlint-baseline.xml"
188     jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
191 tasks.withType(Detekt.class).configureEach {
192     exclude("**/resources/**")
193     exclude("**/tmp/**")
196 tasks.register("listRepositories") {
197     doLast {
198         println "Repositories:"
199         project.repositories.each { println "Name: " + it.name + "; url: " + it.url }
200     }
203 // Task to copy generated baseline profile to the app module nightly variant.
204 tasks.register("copyBaselineProfile", DefaultTask) {
205     doLast {
206         File profileFile = fileTree('benchmark/build/outputs') {
207             include '**/*baseline-prof.txt'
208         }.getSingleFile()
209         def destinationPath = Paths.get("app", "src", "nightly", "baselineProfiles", "baseline-prof.txt")
210         File destinationDir = destinationPath.toFile().parentFile
211         if (!destinationDir.exists()) {
212             destinationDir.mkdirs()
213         }
214         Files.copy(profileFile.toPath(), destinationPath, StandardCopyOption.REPLACE_EXISTING)
215     }