Bug 1822393 - enable Werror compiler args for geckoview dependencies. r=gl,geckoview...
[gecko.git] / mobile / android / fenix / build.gradle
blob4a898eb26273d4fba9a5f4acb4eede4e039e8898
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         if (!System.env.MOZ_AUTOMATION && gradle.mozconfig.substs.MOZ_ARTIFACT_BUILDS) {
14             mavenLocal()
15         }
17         maven {
18             name "Mozilla Nightly"
19             url "https://nightly.maven.mozilla.org/maven2"
20             content {
21                 // Improve performance: only check moz maven for mozilla deps.
22                 includeGroupByRegex RepoMatching.mozilla
23             }
24         }
26         maven {
27             name "Mozilla"
28             url "https://maven.mozilla.org/maven2"
29             content {
30                 // Improve performance: only check moz maven for mozilla deps.
31                 includeGroupByRegex RepoMatching.mozilla
32             }
33         }
35         if (ExtraRepositories.mozillaStaging) {
36             maven {
37                 name "Mozilla Staging"
38                 url "https://maven-default.stage.mozaws.net/maven2"
39                 content {
40                     // Improve performance: only check moz maven for mozilla deps.
41                     includeGroupByRegex RepoMatching.mozilla
42                 }
43             }
44         }
46         if (project.hasProperty("googleRepo")) {
47             maven {
48                 name "Google"
49                 allowInsecureProtocol true // Local Nexus in CI uses HTTP
50                 url project.property("googleRepo")
51             }
52         } else {
53             google() {
54                 content {
55                     // Improve performance: only check google maven for google deps.
56                     includeGroupByRegex RepoMatching.androidx
57                     includeGroupByRegex RepoMatching.comAndroid
58                     includeGroupByRegex RepoMatching.comGoogle
59                 }
60             }
61         }
63         if (project.hasProperty("centralRepo")) {
64             maven {
65                 name "MavenCentral"
66                 url project.property("centralRepo")
67                 allowInsecureProtocol true // Local Nexus in CI uses HTTP
68             }
69         } else {
70             mavenCentral() {
71                 content {
72                     // Improve security: don't search deps with known repos.
73                     excludeGroupByRegex RepoMatching.mozilla
74                     excludeGroupByRegex RepoMatching.androidx
75                     excludeGroupByRegex RepoMatching.comAndroid
76                 }
77             }
78         }
79     }
81     dependencies {
82         classpath ComponentsDependencies.tools_androidgradle
83         classpath ComponentsDependencies.tools_kotlingradle
84         classpath FenixDependencies.tools_benchmarkgradle
85         classpath ComponentsDependencies.androidx_safeargs
86         classpath FenixDependencies.osslicenses_plugin
87         classpath "org.mozilla.telemetry:glean-gradle-plugin:${Versions.mozilla_glean}"
88         classpath "${ApplicationServicesConfig.groupId}:tooling-nimbus-gradle:${ApplicationServicesConfig.version}"
90         // NOTE: Do not place your application dependencies here; they belong
91         // in the individual module build.gradle files
92     }
94     // Variables in plugins {} aren't directly supported. Hack around it by setting an
95     // intermediate variable which can pull from FenixDependenciesPlugin.kt and be used later.
96     ext {
97         detekt_plugin = Versions.detekt
98         ksp_plugin = Versions.ksp_plugin
99         protobuf_plugin = FenixVersions.protobuf_plugin
100         python_envs_plugin = Versions.python_envs_plugin
101     }
104 plugins {
105     id("io.gitlab.arturbosch.detekt").version("$detekt_plugin")
106     id("com.google.devtools.ksp").version("$ksp_plugin")
109 allprojects {
110     // This logic is duplicated in the buildscript block: I don't know how to fix that.
111     repositories {
112         if (!System.env.MOZ_AUTOMATION && gradle.mozconfig.substs.MOZ_ARTIFACT_BUILDS) {
113             mavenLocal()
114         }
116         maven {
117             name "Mozilla Nightly"
118             url "https://nightly.maven.mozilla.org/maven2"
119             content {
120                 // Improve performance: only check moz maven for mozilla deps.
121                 includeGroupByRegex RepoMatching.mozilla
122             }
123         }
125         maven {
126             name "Mozilla"
127             url "https://maven.mozilla.org/maven2"
128             content {
129                 // Improve performance: only check moz maven for mozilla deps.
130                 includeGroupByRegex RepoMatching.mozilla
131             }
132         }
134         if (ExtraRepositories.mozillaStaging) {
135             maven {
136                 name "Mozilla Staging"
137                 url "https://maven-default.stage.mozaws.net/maven2"
138                 content {
139                     // Improve performance: only check moz maven for mozilla deps.
140                     includeGroupByRegex RepoMatching.mozilla
141                 }
142             }
143         }
145         if (project.hasProperty("googleRepo")) {
146             maven {
147                 name "Google"
148                 url project.property("googleRepo")
149                 allowInsecureProtocol true // Local Nexus in CI uses HTTP
150             }
151         } else {
152             google() {
153                 content {
154                     // Improve performance: only check google maven for google deps.
155                     includeGroupByRegex RepoMatching.androidx
156                     includeGroupByRegex RepoMatching.comAndroid
157                     includeGroupByRegex RepoMatching.comGoogle
158                 }
159             }
160         }
162         if (project.hasProperty("centralRepo")) {
163             maven {
164                 name "MavenCentral"
165                 url project.property("centralRepo")
166                 allowInsecureProtocol true // Local Nexus in CI uses HTTP
167             }
168         } else {
169             mavenCentral() {
170                 content {
171                     // Improve security: don't search deps with known repos.
172                     excludeGroupByRegex RepoMatching.mozilla
173                     excludeGroupByRegex RepoMatching.androidx
174                     excludeGroupByRegex RepoMatching.comAndroid
175                 }
176             }
177         }
178     }
180     tasks.withType(KotlinCompile).configureEach {
181         kotlinOptions.allWarningsAsErrors = true
182         kotlinOptions.freeCompilerArgs += [
183             "-opt-in=kotlin.RequiresOptIn", "-Xjvm-default=all-compatibility"
184         ]
185     }
188 subprojects {
189     afterEvaluate {
190         kotlin {
191             jvmToolchain(config.jvmTargetCompatibility)
192         }
193     }
196 tasks.register('clean', Delete) {
197     delete rootProject.layout.buildDirectory
200 detekt {
201     input = files("$projectDir/app/src")
202     config = files("$projectDir/config/detekt.yml")
204     reports {
205         html {
206             enabled = true
207             destination = file("$projectDir/build/reports/detekt.html")
208         }
209         xml {
210             enabled = false
211         }
212         txt {
213             enabled = false
214         }
215     }
218 tasks.withType(Detekt).configureEach() {
219     autoCorrect = true
221     exclude "**/test/**"
222     exclude "**/androidTest/**"
223     exclude "**/build/**"
224     exclude "**/resources/**"
225     exclude "**/tmp/**"
228 // Apply same path exclusions as for the main task
229 tasks.withType(DetektCreateBaselineTask).configureEach() {
230     exclude "**/test/**"
231     exclude "**/androidTest/**"
232     exclude "**/build/**"
233     exclude "**/resources/**"
234     exclude "**/tmp/**"
237 configurations {
238     ktlint
241 dependencies {
242     ktlint("com.pinterest:ktlint:${Versions.ktlint}") {
243         attributes {
244             attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
245         }
246     }
248     detekt project(":mozilla-detekt-rules")
249     detekt "io.gitlab.arturbosch.detekt:detekt-cli:${Versions.detekt}"
252 tasks.register('ktlint', JavaExec) {
253     group = "verification"
254     description = "Check Kotlin code style."
255     classpath = configurations.ktlint
256     mainClass.set("com.pinterest.ktlint.Main")
257     args "app/src/**/*.kt", "!**/build/**/*.kt", "--baseline=ktlint-baseline.xml"
260 tasks.register('ktlintFormat', JavaExec) {
261     description = "Fix Kotlin code style deviations."
262     classpath = configurations.ktlint
263     mainClass.set("com.pinterest.ktlint.Main")
264     args "-F", "app/src/**/*.kt", "!**/build/**/*.kt", "--baseline=ktlint-baseline.xml"
265     jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
268 tasks.withType(Detekt.class).configureEach {
269     exclude("**/resources/**")
270     exclude("**/tmp/**")
273 tasks.register("listRepositories") {
274     doLast {
275         println "Repositories:"
276         project.repositories.each { println "Name: " + it.name + "; url: " + it.url }
277     }
280 // Task to copy generated baseline profile to the app module nightly variant.
281 tasks.register("copyBaselineProfile", DefaultTask) {
282     doLast {
283         File profileFile = fileTree('benchmark/build/outputs') {
284             include '**/*baseline-prof.txt'
285         }.getSingleFile()
286         def destinationPath = Paths.get("app", "src", "nightly", "baselineProfiles", "baseline-prof.txt")
287         File destinationDir = destinationPath.toFile().parentFile
288         if (!destinationDir.exists()) {
289             destinationDir.mkdirs()
290         }
291         Files.copy(profileFile.toPath(), destinationPath, StandardCopyOption.REPLACE_EXISTING)
292     }