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.
10 gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
13 if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
14 allowInsecureProtocol = true
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
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.
34 detekt_plugin = Versions.detekt
35 python_envs_plugin = Versions.python_envs_plugin
36 ksp_plugin = Versions.ksp_plugin
41 id "io.gitlab.arturbosch.detekt" version "$detekt_plugin"
42 id("com.google.devtools.ksp").version("$ksp_plugin")
46 input = files("$projectDir/app")
47 config = files("$projectDir/quality/detekt.yml")
48 baseline = file("$projectDir/quality/detekt-baseline.xml")
53 destination = file("$projectDir/build/reports/detekt.html")
64 tasks.withType(Detekt).configureEach() {
68 exclude "**/androidTest/**"
70 exclude "**/resources/**"
74 // Apply same path exclusions as for the main task
75 tasks.withType(DetektCreateBaselineTask).configureEach() {
77 exclude "**/androidTest/**"
79 exclude "**/resources/**"
85 gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
88 if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
89 allowInsecureProtocol = true
95 url "${gradle.mozconfig.topobjdir}/gradle/maven"
103 jvmToolchain(config.jvmTargetCompatibility)
107 tasks.withType(KotlinCompile).configureEach { task ->
108 // Translate Kotlin messages like "w: ..." and "e: ..." into
109 // "...: warning: ..." and "...: error: ...", to make Treeherder understand.
112 if (it.startsWith("e: warnings found")) {
116 if (it.startsWith('w: ') || it.startsWith('e: ')) {
117 def matches = (it =~ /([ew]): (.+):(\d+):(\d+) (.*)/)
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.
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"
132 } as StandardOutputListener
135 logging.addStandardErrorListener(listener)
138 logging.removeStandardErrorListener(listener)
143 tasks.register('clean', Delete) {
144 delete rootProject.layout.buildDirectory
153 ktlint("com.pinterest:ktlint:${Versions.ktlint}") {
155 attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
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") {
178 println "Repositories:"
179 project.repositories.each { println "Name: " + it.name + "; url: " + it.url }