2024-02-21 18:22:05 +01:00
|
|
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
|
|
|
|
2023-11-28 09:06:47 +01:00
|
|
|
import io.gitlab.arturbosch.detekt.Detekt
|
|
|
|
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
|
|
|
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
2024-02-21 18:22:05 +01:00
|
|
|
import java.nio.file.Files
|
|
|
|
import java.nio.file.Paths
|
|
|
|
import java.nio.file.StandardCopyOption
|
2023-11-28 09:06:47 +01:00
|
|
|
|
|
|
|
buildscript {
|
|
|
|
// This logic is duplicated in the allprojects block: I don't know how to fix that.
|
|
|
|
repositories {
|
2024-08-26 10:00:43 +02:00
|
|
|
gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
|
2023-11-28 09:06:47 +01:00
|
|
|
maven {
|
2024-08-26 10:00:43 +02:00
|
|
|
url repository
|
|
|
|
if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
|
|
|
|
allowInsecureProtocol = true
|
2023-11-28 09:06:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
|
|
|
classpath ComponentsDependencies.tools_androidgradle
|
|
|
|
classpath ComponentsDependencies.tools_kotlingradle
|
|
|
|
classpath FenixDependencies.tools_benchmarkgradle
|
2024-04-14 13:12:20 +02:00
|
|
|
classpath ComponentsDependencies.androidx_safeargs
|
2023-11-28 09:06:47 +01:00
|
|
|
classpath FenixDependencies.osslicenses_plugin
|
|
|
|
classpath "org.mozilla.telemetry:glean-gradle-plugin:${Versions.mozilla_glean}"
|
|
|
|
classpath "${ApplicationServicesConfig.groupId}:tooling-nimbus-gradle:${ApplicationServicesConfig.version}"
|
|
|
|
|
|
|
|
// NOTE: Do not place your application dependencies here; they belong
|
|
|
|
// in the individual module build.gradle files
|
|
|
|
}
|
|
|
|
|
|
|
|
// Variables in plugins {} aren't directly supported. Hack around it by setting an
|
|
|
|
// intermediate variable which can pull from FenixDependenciesPlugin.kt and be used later.
|
|
|
|
ext {
|
|
|
|
detekt_plugin = Versions.detekt
|
|
|
|
ksp_plugin = Versions.ksp_plugin
|
|
|
|
protobuf_plugin = FenixVersions.protobuf_plugin
|
|
|
|
python_envs_plugin = Versions.python_envs_plugin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
plugins {
|
|
|
|
id("io.gitlab.arturbosch.detekt").version("$detekt_plugin")
|
|
|
|
id("com.google.devtools.ksp").version("$ksp_plugin")
|
|
|
|
}
|
|
|
|
|
|
|
|
allprojects {
|
|
|
|
// This logic is duplicated in the buildscript block: I don't know how to fix that.
|
|
|
|
repositories {
|
2024-08-26 10:00:43 +02:00
|
|
|
gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
|
2023-11-28 09:06:47 +01:00
|
|
|
maven {
|
2024-08-26 10:00:43 +02:00
|
|
|
url repository
|
|
|
|
if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
|
|
|
|
allowInsecureProtocol = true
|
2023-11-28 09:06:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.withType(KotlinCompile).configureEach {
|
|
|
|
kotlinOptions.allWarningsAsErrors = true
|
|
|
|
kotlinOptions.freeCompilerArgs += [
|
2024-08-26 10:00:43 +02:00
|
|
|
"-opt-in=kotlin.RequiresOptIn", "-Xjvm-default=all-compatibility"
|
2023-11-28 09:06:47 +01:00
|
|
|
]
|
|
|
|
}
|
2024-08-26 10:00:43 +02:00
|
|
|
|
|
|
|
ext {
|
|
|
|
gleanParserOverride = "14.4.0"
|
|
|
|
}
|
2023-11-28 09:06:47 +01:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:56:09 +01:00
|
|
|
subprojects {
|
|
|
|
afterEvaluate {
|
2024-06-01 16:29:02 +02:00
|
|
|
kotlin {
|
|
|
|
jvmToolchain(config.jvmTargetCompatibility)
|
2024-01-30 15:56:09 +01:00
|
|
|
}
|
|
|
|
}
|
2024-08-26 10:00:43 +02:00
|
|
|
|
|
|
|
tasks.withType(KotlinCompile).configureEach { task ->
|
|
|
|
// Translate Kotlin messages like "w: ..." and "e: ..." into
|
|
|
|
// "...: warning: ..." and "...: error: ...", to make Treeherder understand.
|
|
|
|
def listener = {
|
|
|
|
|
|
|
|
if (it.startsWith("e: warnings found")) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (it.startsWith('w: ') || it.startsWith('e: ')) {
|
|
|
|
def matches = (it =~ /([ew]): (.+):(\d+):(\d+) (.*)/)
|
|
|
|
if (!matches) {
|
|
|
|
logger.quiet "kotlinc message format has changed!"
|
|
|
|
if (it.startsWith('w: ')) {
|
|
|
|
// For warnings, don't continue because we don't want to throw an
|
|
|
|
// exception. For errors, we want the exception so that the new error
|
|
|
|
// message format gets translated properly.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
def (_, type, file, line, column, message) = matches[0]
|
|
|
|
type = (type == 'w') ? 'warning' : 'error'
|
|
|
|
// Use logger.lifecycle, which does not go through stderr again.
|
|
|
|
logger.lifecycle "$file:$line:$column: $type: $message"
|
|
|
|
}
|
|
|
|
} as StandardOutputListener
|
|
|
|
|
|
|
|
doFirst {
|
|
|
|
logging.addStandardErrorListener(listener)
|
|
|
|
}
|
|
|
|
doLast {
|
|
|
|
logging.removeStandardErrorListener(listener)
|
|
|
|
}
|
|
|
|
}
|
2024-01-30 15:56:09 +01:00
|
|
|
}
|
|
|
|
|
2023-11-28 09:06:47 +01:00
|
|
|
tasks.register('clean', Delete) {
|
2024-01-30 15:56:09 +01:00
|
|
|
delete rootProject.layout.buildDirectory
|
2023-11-28 09:06:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
detekt {
|
|
|
|
input = files("$projectDir/app/src")
|
|
|
|
config = files("$projectDir/config/detekt.yml")
|
|
|
|
|
|
|
|
reports {
|
|
|
|
html {
|
|
|
|
enabled = true
|
|
|
|
destination = file("$projectDir/build/reports/detekt.html")
|
|
|
|
}
|
|
|
|
xml {
|
|
|
|
enabled = false
|
|
|
|
}
|
|
|
|
txt {
|
|
|
|
enabled = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.withType(Detekt).configureEach() {
|
|
|
|
autoCorrect = true
|
|
|
|
|
|
|
|
exclude "**/test/**"
|
|
|
|
exclude "**/androidTest/**"
|
|
|
|
exclude "**/build/**"
|
|
|
|
exclude "**/resources/**"
|
|
|
|
exclude "**/tmp/**"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply same path exclusions as for the main task
|
|
|
|
tasks.withType(DetektCreateBaselineTask).configureEach() {
|
|
|
|
exclude "**/test/**"
|
|
|
|
exclude "**/androidTest/**"
|
|
|
|
exclude "**/build/**"
|
|
|
|
exclude "**/resources/**"
|
|
|
|
exclude "**/tmp/**"
|
|
|
|
}
|
|
|
|
|
|
|
|
configurations {
|
|
|
|
ktlint
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
|
|
|
ktlint("com.pinterest:ktlint:${Versions.ktlint}") {
|
|
|
|
attributes {
|
|
|
|
attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
detekt project(":mozilla-detekt-rules")
|
|
|
|
detekt "io.gitlab.arturbosch.detekt:detekt-cli:${Versions.detekt}"
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register('ktlint', JavaExec) {
|
|
|
|
group = "verification"
|
|
|
|
description = "Check Kotlin code style."
|
|
|
|
classpath = configurations.ktlint
|
|
|
|
mainClass.set("com.pinterest.ktlint.Main")
|
|
|
|
args "app/src/**/*.kt", "!**/build/**/*.kt", "--baseline=ktlint-baseline.xml"
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register('ktlintFormat', JavaExec) {
|
|
|
|
description = "Fix Kotlin code style deviations."
|
|
|
|
classpath = configurations.ktlint
|
|
|
|
mainClass.set("com.pinterest.ktlint.Main")
|
|
|
|
args "-F", "app/src/**/*.kt", "!**/build/**/*.kt", "--baseline=ktlint-baseline.xml"
|
|
|
|
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.withType(Detekt.class).configureEach {
|
|
|
|
exclude("**/resources/**")
|
|
|
|
exclude("**/tmp/**")
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register("listRepositories") {
|
|
|
|
doLast {
|
|
|
|
println "Repositories:"
|
|
|
|
project.repositories.each { println "Name: " + it.name + "; url: " + it.url }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-21 18:22:05 +01:00
|
|
|
// Task to copy generated baseline profile to the app module nightly variant.
|
|
|
|
tasks.register("copyBaselineProfile", DefaultTask) {
|
|
|
|
doLast {
|
|
|
|
File profileFile = fileTree('benchmark/build/outputs') {
|
|
|
|
include '**/*baseline-prof.txt'
|
|
|
|
}.getSingleFile()
|
|
|
|
def destinationPath = Paths.get("app", "src", "nightly", "baselineProfiles", "baseline-prof.txt")
|
|
|
|
File destinationDir = destinationPath.toFile().parentFile
|
|
|
|
if (!destinationDir.exists()) {
|
|
|
|
destinationDir.mkdirs()
|
|
|
|
}
|
|
|
|
Files.copy(profileFile.toPath(), destinationPath, StandardCopyOption.REPLACE_EXISTING)
|
|
|
|
}
|
|
|
|
}
|