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
11 // This logic is duplicated in the allprojects block: I don't know how to fix that.
13 if (!System.env.MOZ_AUTOMATION && gradle.mozconfig.substs.MOZ_ARTIFACT_BUILDS) {
18 name "Mozilla Nightly"
19 url "https://nightly.maven.mozilla.org/maven2"
21 // Improve performance: only check moz maven for mozilla deps.
22 includeGroupByRegex RepoMatching.mozilla
28 url "https://maven.mozilla.org/maven2"
30 // Improve performance: only check moz maven for mozilla deps.
31 includeGroupByRegex RepoMatching.mozilla
35 if (ExtraRepositories.mozillaStaging) {
37 name "Mozilla Staging"
38 url "https://maven-default.stage.mozaws.net/maven2"
40 // Improve performance: only check moz maven for mozilla deps.
41 includeGroupByRegex RepoMatching.mozilla
46 if (project.hasProperty("googleRepo")) {
49 allowInsecureProtocol true // Local Nexus in CI uses HTTP
50 url project.property("googleRepo")
55 // Improve performance: only check google maven for google deps.
56 includeGroupByRegex RepoMatching.androidx
57 includeGroupByRegex RepoMatching.comAndroid
58 includeGroupByRegex RepoMatching.comGoogle
63 if (project.hasProperty("centralRepo")) {
66 url project.property("centralRepo")
67 allowInsecureProtocol true // Local Nexus in CI uses HTTP
72 // Improve security: don't search deps with known repos.
73 excludeGroupByRegex RepoMatching.mozilla
74 excludeGroupByRegex RepoMatching.androidx
75 excludeGroupByRegex RepoMatching.comAndroid
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
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.
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
105 id("io.gitlab.arturbosch.detekt").version("$detekt_plugin")
106 id("com.google.devtools.ksp").version("$ksp_plugin")
110 // This logic is duplicated in the buildscript block: I don't know how to fix that.
112 if (!System.env.MOZ_AUTOMATION && gradle.mozconfig.substs.MOZ_ARTIFACT_BUILDS) {
117 name "Mozilla Nightly"
118 url "https://nightly.maven.mozilla.org/maven2"
120 // Improve performance: only check moz maven for mozilla deps.
121 includeGroupByRegex RepoMatching.mozilla
127 url "https://maven.mozilla.org/maven2"
129 // Improve performance: only check moz maven for mozilla deps.
130 includeGroupByRegex RepoMatching.mozilla
134 if (ExtraRepositories.mozillaStaging) {
136 name "Mozilla Staging"
137 url "https://maven-default.stage.mozaws.net/maven2"
139 // Improve performance: only check moz maven for mozilla deps.
140 includeGroupByRegex RepoMatching.mozilla
145 if (project.hasProperty("googleRepo")) {
148 url project.property("googleRepo")
149 allowInsecureProtocol true // Local Nexus in CI uses HTTP
154 // Improve performance: only check google maven for google deps.
155 includeGroupByRegex RepoMatching.androidx
156 includeGroupByRegex RepoMatching.comAndroid
157 includeGroupByRegex RepoMatching.comGoogle
162 if (project.hasProperty("centralRepo")) {
165 url project.property("centralRepo")
166 allowInsecureProtocol true // Local Nexus in CI uses HTTP
171 // Improve security: don't search deps with known repos.
172 excludeGroupByRegex RepoMatching.mozilla
173 excludeGroupByRegex RepoMatching.androidx
174 excludeGroupByRegex RepoMatching.comAndroid
180 tasks.withType(KotlinCompile).configureEach {
181 kotlinOptions.allWarningsAsErrors = true
182 kotlinOptions.freeCompilerArgs += [
183 "-opt-in=kotlin.RequiresOptIn", "-Xjvm-default=all-compatibility"
191 jvmToolchain(config.jvmTargetCompatibility)
196 tasks.register('clean', Delete) {
197 delete rootProject.layout.buildDirectory
201 input = files("$projectDir/app/src")
202 config = files("$projectDir/config/detekt.yml")
207 destination = file("$projectDir/build/reports/detekt.html")
218 tasks.withType(Detekt).configureEach() {
222 exclude "**/androidTest/**"
223 exclude "**/build/**"
224 exclude "**/resources/**"
228 // Apply same path exclusions as for the main task
229 tasks.withType(DetektCreateBaselineTask).configureEach() {
231 exclude "**/androidTest/**"
232 exclude "**/build/**"
233 exclude "**/resources/**"
242 ktlint("com.pinterest:ktlint:${Versions.ktlint}") {
244 attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
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/**")
273 tasks.register("listRepositories") {
275 println "Repositories:"
276 project.repositories.each { println "Name: " + it.name + "; url: " + it.url }
280 // Task to copy generated baseline profile to the app module nightly variant.
281 tasks.register("copyBaselineProfile", DefaultTask) {
283 File profileFile = fileTree('benchmark/build/outputs') {
284 include '**/*baseline-prof.txt'
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()
291 Files.copy(profileFile.toPath(), destinationPath, StandardCopyOption.REPLACE_EXISTING)