Revision control

Copy as Markdown

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
google()
maven {
}
maven {
name = "Mozilla"
content {
// Improve performance: only check moz maven for mozilla deps.
includeGroupByRegex "org\\.mozilla\\..*"
}
}
maven {
name = "Mozilla Nightly"
content {
// Improve performance: only check moz maven for mozilla deps.
includeGroupByRegex "org\\.mozilla\\..*"
}
}
}
dependencies {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath libs.android.gradle.plugin
classpath libs.kotlin.gradle.plugin
classpath libs.mozilla.glean.gradle.plugin
classpath libs.mozilla.rust.android.gradle
// Yes, this is unusual. We want to access some host-specific
// computation at build time.
classpath libs.jna
}
}
plugins {
alias libs.plugins.detekt
alias libs.plugins.kotlin.serialization apply false
}
allprojects {
repositories {
google()
mavenCentral()
maven {
name = "Mozilla"
content {
// Improve performance: only check moz maven for mozilla deps.
includeGroupByRegex "org\\.mozilla\\..*"
}
}
maven {
name = "Mozilla Nightly"
content {
// Improve performance: only check moz maven for mozilla deps.
includeGroupByRegex "org\\.mozilla\\..*"
}
}
}
}
task clean(type: Delete) {
delete rootProject.layout.buildDirectory
}
// Avoid Gradle namespace collision. This is here, rather than in `buildscript
// { ... }`, to avoid issues with importing.
import com.sun.jna.Platform as DefaultPlatform
// We require `--locked` in CI, but not for local builds.
// Unlike the Cargo targets below, this can't be overridden by `local.properties` (mainly
// because doing so seems pointless, not for any security reason)
ext.extraCargoBuildArguments = []
if (System.getenv("CI")) {
ext.extraCargoBuildArguments = ["--locked"]
}
// The Cargo targets to invoke. The mapping from short name to target
// triple is defined by the `rust-android-gradle` plugin.
// They can be overwritten in `local.properties` by the `rust.targets`
// attribute.
ext.rustTargets = [
'arm',
'arm64',
'x86_64',
]
// Generate libs for our current platform so we can run unit tests.
switch (DefaultPlatform.RESOURCE_PREFIX) {
case 'darwin-x86-64':
ext.nativeRustTarget = 'darwin-x86-64'
break
case 'darwin-aarch64':
ext.nativeRustTarget = 'darwin-aarch64'
break
case 'linux-x86-64':
ext.nativeRustTarget = 'linux-x86-64'
break
}
ext.rustTargets += ext.nativeRustTarget
subprojects {
group = "org.mozilla.appservices"
apply plugin: 'maven-publish'
tasks.withType(AbstractTestTask).configureEach {
failOnNoDiscoveredTests = false
}
tasks.withType(Test).configureEach {
jvmArgs("--enable-native-access=ALL-UNNAMED")
}
// Kotlin settings applicable to all modules.
afterEvaluate{
if (it.hasProperty('android')) {
android {
buildToolsVersion = rootProject.config.buildToolsVersion
compileOptions {
sourceCompatibility = JavaVersion.toVersion(rootProject.config.jvmTargetCompatibility)
targetCompatibility = JavaVersion.toVersion(rootProject.config.jvmTargetCompatibility)
}
publishing {
singleVariant('release') {
withSourcesJar()
}
}
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
compilerOptions.allWarningsAsErrors = true
compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.fromTarget("${rootProject.config.jvmTargetCompatibility}")
}
}
// This allows to invoke Gradle like `./gradlew publishToRootProjectBuildDir` (equivalent to
// `./gradlew publish`) and also `./gradlew publishToProjectBuildDir`.
publishing {
repositories {
maven {
name = "rootProjectBuildDir"
url = rootProject.layout.buildDirectory.dir("maven")
}
maven {
name = "projectBuildDir"
url = layout.buildDirectory.dir("maven")
}
}
}
}
// Configure some environment variables, per toolchain, that will apply during
// the Cargo build. We assume that the `libs/` directory has been populated
// before invoking Gradle (or Cargo).
ext.cargoExec = { spec, toolchain ->
spec.environment("NSS_STATIC", "1")
spec.environment("NSS_DIR", new File(rootProject.rootDir, "libs/${toolchain.folder}/nss").absolutePath)
if (toolchain.folder.startsWith("android/")) {
spec.environment("BINDGEN_EXTRA_CLANG_ARGS", "--target=${toolchain.compilerTriple}${rootProject.config.minSdkVersion}")
}
}
detekt {
source.setFrom(fileTree(dir: "${projectDir}/components", excludes: ["external", "**/build", "**/generated", "**/templates"]))
buildUponDefaultConfig = true
config.setFrom(files("${projectDir}/.detekt.yml"))
reports {
xml.required = false
}
}
configurations {
ktlint
}
dependencies {
ktlint(libs.ktlint) {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
}
}
}
tasks.register("ktlint", JavaExec) {
group = "verification"
description = "Check Kotlin code style."
classpath = configurations.ktlint
mainClass = "com.pinterest.ktlint.Main"
args "${projectDir}/components/**/*.kt", "!**/build", "!**/templates/**", "!components/external", "!**/generated/**"
}
tasks.register("ktlintFormat", JavaExec) {
group = "formatting"
description = "Fix Kotlin code style deviations."
classpath = configurations.ktlint
mainClass = "com.pinterest.ktlint.Main"
args "-F", "${projectDir}/components/**/*.kt", "!**/build", "!**/templates/**", "!components/external", "!**/generated/**"
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
}
// Extremely unsophisticated way to publish a local development version while hiding implementation details.
//
// This shells out to a python script that tries to detect whether the working directory has changed since the last
// time it was run, and it so then it shells out to `./gradlew publishToMavenLocal -Plocal=<timestamp>` to publish
// a new version of of the code with an auto-incrementing version number.
//
// It would be nice to implement this natively in gradle using gradle's own change-detection facilities, but I don't know
// enough about gradle to take that on. At least this approach gives a nice stable `./gradlew autoPublishForLocalDevelopment`
// interface for consumers.
task autoPublishForLocalDevelopment(type: Exec) {
commandLine "./automation/publish_to_maven_local_if_modified.py"
}
task printNdkVersion {
doLast {
println config.ndkVersion
}
}