diff --git a/build-scripts/component-common.gradle b/build-scripts/component-common.gradle index 9c298ea96..5b4a2b20d 100644 --- a/build-scripts/component-common.gradle +++ b/build-scripts/component-common.gradle @@ -43,10 +43,10 @@ kotlin { } dependencies { - testImplementation "junit:junit:$junit_version" - testImplementation "org.robolectric:robolectric:$robolectric_core_version" - testImplementation "org.mockito:mockito-core:$mockito_core_version" + testImplementation libs.junit + testImplementation libs.mockito + testImplementation libs.robolectric - androidTestImplementation "androidx.test:runner:$androidx_test_version" - androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_core_version" + androidTestImplementation libs.test.espresso.core + androidTestImplementation libs.test.runner } diff --git a/build-scripts/protobuf-common.gradle b/build-scripts/protobuf-common.gradle index 6975daf32..c2391f630 100644 --- a/build-scripts/protobuf-common.gradle +++ b/build-scripts/protobuf-common.gradle @@ -20,7 +20,7 @@ android { protobuf { protoc { - artifact = "com.google.protobuf:protoc:$protobuf_version" + artifact = libs.protoc.get().toString() // https://github.com/google/protobuf-gradle-plugin/issues/563 } generateProtoTasks { all().each { task -> @@ -34,5 +34,5 @@ protobuf { } dependencies { - implementation "com.google.protobuf:protobuf-javalite:$protobuf_version" + implementation libs.protobuf } diff --git a/build.gradle b/build.gradle index baa985098..58760bb17 100644 --- a/build.gradle +++ b/build.gradle @@ -1,34 +1,6 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - - ext { - kotlin_version = '1.9.22' - kotlin_coroutines_version = '1.7.3' - jna_version = '5.14.0' - android_gradle_plugin_version = '8.0.2' - android_components_version = '122.0' - glean_version = '57.0.0' - - // NOTE: AndroidX libraries should be synced with AC to avoid compatibility issues - androidx_annotation_version = '1.7.1' - androidx_core_version = '1.12.0' - androidx_test_version = '1.5.0' - androidx_test_junit_version = '1.1.5' - androidx_work_testing_version = '2.7.1' - espresso_core_version = '3.5.1' - - detekt_version = '1.23.5' - ktlint_version = '0.50.0' - gradle_download_task_version = '5.2.1' - junit_version = '4.13.2' - mockito_core_version = '5.10.0' - robolectric_core_version = '4.11.1' - rust_android_gradle_version = '0.9.3' - protobuf_version = '3.21.10' - gradle_protobuf_version = '0.9.4' - } - ext.build = [ ndkVersion: "25.2.9519653", // Keep it in sync in TC Dockerfile. @@ -56,36 +28,26 @@ buildscript { } dependencies { - classpath "com.android.tools.build:gradle:$android_gradle_plugin_version" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files - classpath "org.mozilla.rust-android-gradle:plugin:$rust_android_gradle_version" + classpath libs.kotlin.gradle.plugin + classpath libs.mozilla.glean.gradle.plugin + classpath libs.mozilla.rust.android.gradle + classpath libs.tools.android.plugin // Yes, this is unusual. We want to access some host-specific // computation at build time. - classpath "net.java.dev.jna:jna:$jna_version" - - // Downloading libs/ archives from Taskcluster. - classpath "de.undercouch:gradle-download-task:$gradle_download_task_version" - - classpath "com.google.protobuf:protobuf-gradle-plugin:$gradle_protobuf_version" - - // Since the Glean version depends on the Android components version, - // it is very important to use a modern version of Glean and, ideally, - // let this come from the embedding product itself. - classpath "org.mozilla.telemetry:glean-gradle-plugin:$glean_version" - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath libs.jna } } plugins { - id "io.gitlab.arturbosch.detekt" version "$detekt_version" + alias libs.plugins.detekt + alias libs.plugins.gradle.download.task // Downloading libs/archives from Taskcluster. + alias libs.plugins.protobuf.gradle apply false } -apply plugin: 'de.undercouch.download' - allprojects { repositories { google() @@ -293,7 +255,6 @@ ext.cargoExec = { spec, toolchain -> } detekt { - toolVersion = "$detekt_version" input = files( fileTree(dir: "${projectDir}/components", excludes: ["external", "**/generated", "**/templates"]), "${projectDir}/gradle-plugin", @@ -315,7 +276,7 @@ configurations { } dependencies { - ktlint("com.pinterest:ktlint:$ktlint_version") { + ktlint(libs.ktlint) { attributes { attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL)) } diff --git a/components/autofill/android/build.gradle b/components/autofill/android/build.gradle index df449bf0a..96d9372ac 100644 --- a/components/autofill/android/build.gradle +++ b/components/autofill/android/build.gradle @@ -9,8 +9,8 @@ dependencies { // Part of the public API. api project(':sync15') - testImplementation "androidx.test:core-ktx:$androidx_test_version" - testImplementation "androidx.work:work-testing:$androidx_work_testing_version" + testImplementation libs.test.core + testImplementation libs.test.work testImplementation project(":syncmanager") } diff --git a/components/fxa-client/android/build.gradle b/components/fxa-client/android/build.gradle index 2a7203e03..ad442f107 100644 --- a/components/fxa-client/android/build.gradle +++ b/components/fxa-client/android/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.jetbrains.python.envs" version "0.0.26" + alias libs.plugins.gradle.python.envs } apply from: "$rootDir/build-scripts/component-common.gradle" @@ -15,9 +15,9 @@ android { dependencies { api project(':sync15') - implementation "org.mozilla.telemetry:glean:$glean_version" + implementation libs.mozilla.glean - testImplementation "org.mozilla.telemetry:glean-native-forUnitTests:$glean_version" + testImplementation libs.mozilla.glean.native.tests } ext.configureUniFFIBindgen("../src/fxa_client.udl") diff --git a/components/logins/android/build.gradle b/components/logins/android/build.gradle index 180d9d1a5..e00720ec4 100644 --- a/components/logins/android/build.gradle +++ b/components/logins/android/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.jetbrains.python.envs" version "0.0.26" + alias libs.plugins.gradle.python.envs } apply from: "$rootDir/build-scripts/component-common.gradle" @@ -18,11 +18,11 @@ dependencies { // Part of the public API. api project(':sync15') - implementation "org.mozilla.telemetry:glean:$glean_version" + implementation libs.mozilla.glean - testImplementation "androidx.test:core-ktx:$androidx_test_version" - testImplementation "androidx.work:work-testing:$androidx_work_testing_version" - testImplementation "org.mozilla.telemetry:glean-native-forUnitTests:$glean_version" + testImplementation libs.mozilla.glean.native.tests + testImplementation libs.test.core + testImplementation libs.test.work testImplementation project(":syncmanager") } diff --git a/components/nimbus/android/build.gradle b/components/nimbus/android/build.gradle index da68f3b30..b44fd1a6b 100644 --- a/components/nimbus/android/build.gradle +++ b/components/nimbus/android/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.jetbrains.python.envs" version "0.0.26" + alias libs.plugins.gradle.python.envs } apply from: "$rootDir/build-scripts/component-common.gradle" @@ -14,18 +14,17 @@ android { } dependencies { - implementation "androidx.annotation:annotation:$androidx_annotation_version" - - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version" - api project(":remotesettings") - implementation "org.mozilla.telemetry:glean:$glean_version" - implementation "androidx.core:core-ktx:$androidx_core_version" - testImplementation "androidx.test:core-ktx:$androidx_test_version" - testImplementation "androidx.test.ext:junit-ktx:$androidx_test_junit_version" - testImplementation "androidx.work:work-testing:$androidx_work_testing_version" - testImplementation "org.mozilla.telemetry:glean-native-forUnitTests:$glean_version" + implementation libs.androidx.core + implementation libs.androidx.annotation + implementation libs.kotlinx.coroutines + implementation libs.mozilla.glean + + testImplementation libs.mozilla.glean.native.tests + testImplementation libs.test.core + testImplementation libs.test.junit.ext + testImplementation libs.test.work } ext.configureUniFFIBindgen("../src/nimbus.udl") diff --git a/components/places/android/build.gradle b/components/places/android/build.gradle index d44e52cb7..169caf083 100644 --- a/components/places/android/build.gradle +++ b/components/places/android/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.jetbrains.python.envs" version "0.0.26" + alias libs.plugins.gradle.python.envs } apply from: "$rootDir/build-scripts/component-common.gradle" @@ -17,11 +17,11 @@ dependencies { // Part of the public API. api project(':sync15') - implementation "org.mozilla.telemetry:glean:$glean_version" + implementation libs.mozilla.glean - testImplementation "androidx.test:core-ktx:$androidx_test_version" - testImplementation "androidx.work:work-testing:$androidx_work_testing_version" - testImplementation "org.mozilla.telemetry:glean-native-forUnitTests:$glean_version" + testImplementation libs.mozilla.glean.native.tests + testImplementation libs.test.core + testImplementation libs.test.work testImplementation project(':syncmanager') } diff --git a/components/remote_settings/android/build.gradle b/components/remote_settings/android/build.gradle index 37745c96b..fb2fb7bfe 100644 --- a/components/remote_settings/android/build.gradle +++ b/components/remote_settings/android/build.gradle @@ -10,6 +10,6 @@ ext.dependsOnTheMegazord() ext.configurePublish() dependencies { - testImplementation("org.mozilla.components:concept-fetch:$android_components_version") + testImplementation libs.mozilla.concept.fetch testImplementation project(":httpconfig") } diff --git a/components/support/android/build.gradle b/components/support/android/build.gradle index ed927ba5e..a3bb384cb 100644 --- a/components/support/android/build.gradle +++ b/components/support/android/build.gradle @@ -1,4 +1,5 @@ apply from: "$rootDir/build-scripts/component-common.gradle" +apply from: "$rootDir/build-scripts/protobuf-common.gradle" apply from: "$rootDir/publish.gradle" android { @@ -6,8 +7,12 @@ android { } dependencies { - implementation "net.java.dev.jna:jna:$jna_version@aar" - implementation "com.google.protobuf:protobuf-javalite:$protobuf_version" + implementation(libs.jna) { + artifact { + extension ="aar" + type = "aar" + } + } } ext.configurePublish() diff --git a/components/sync_manager/android/build.gradle b/components/sync_manager/android/build.gradle index 06cd836a1..5fe79dbb0 100644 --- a/components/sync_manager/android/build.gradle +++ b/components/sync_manager/android/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.jetbrains.python.envs" version "0.0.26" + alias libs.plugins.gradle.python.envs } apply from: "$rootDir/build-scripts/component-common.gradle" @@ -19,13 +19,13 @@ dependencies { // Part of the public API. api project(':sync15') - implementation "org.mozilla.telemetry:glean:$glean_version" - implementation "androidx.core:core-ktx:$androidx_core_version" + implementation libs.androidx.core + implementation libs.mozilla.glean - testImplementation "androidx.test:core-ktx:$androidx_test_version" - testImplementation "androidx.test.ext:junit-ktx:$androidx_test_junit_version" - testImplementation "androidx.work:work-testing:$androidx_work_testing_version" - testImplementation "org.mozilla.telemetry:glean-native-forUnitTests:$glean_version" + testImplementation libs.mozilla.glean.native.tests + testImplementation libs.test.core + testImplementation libs.test.junit.ext + testImplementation libs.test.work } ext.configureUniFFIBindgen("../src/syncmanager.udl") diff --git a/components/viaduct/android/build.gradle b/components/viaduct/android/build.gradle index dae12f33d..dff4160d3 100644 --- a/components/viaduct/android/build.gradle +++ b/components/viaduct/android/build.gradle @@ -7,7 +7,7 @@ android { } dependencies { - api "org.mozilla.components:concept-fetch:$android_components_version" + api libs.mozilla.concept.fetch } ext.dependsOnTheMegazord() diff --git a/components/webext-storage/android/build.gradle b/components/webext-storage/android/build.gradle index 1ca49e550..5860a876e 100644 --- a/components/webext-storage/android/build.gradle +++ b/components/webext-storage/android/build.gradle @@ -7,13 +7,13 @@ // // Part of the public API. // api project(':sync15') -// implementation "org.mozilla.telemetry:glean:$glean_version" -// implementation "androidx.core:core-ktx:$androidx_core_version" +// implementation libs.androidx.core +// implementation libs.mozilla.glean -// testImplementation "androidx.test:core-ktx:$androidx_test_version" -// testImplementation "androidx.test.ext:junit-ktx:$androidx_test_junit_version" -// testImplementation "androidx.work:work-testing:$androidx_work_testing_version" -// testImplementation "org.mozilla.telemetry:glean-native-forUnitTests:$glean_version" +// testImplementation libs.mozilla.glean.native.tests +// testImplementation libs.test.core +// testImplementation libs.test.junit.ext +// testImplementation libs.test.work // } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 000000000..c54dcb6c9 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,97 @@ +# In general, these versions should be kept in sync with AC to avoid introducing +# possible conflicts and compatibility issues. This primarily applies to dependencies +# for shipping code, however. Libraries used only for the build system or testing +# can be safely bumped when convenient. + +[versions] +# AGP +android-plugin = "8.0.2" + +# Google +protobuf = "3.21.10" + +# Kotlin +kotlin-compiler = "1.9.22" +kotlin-dsl = "4.2.1" +kotlinx-coroutines = "1.7.3" + +# Mozilla +android-components = "122.0.1" +glean = "57.0.0" +rust-android-gradle = "0.9.3" + +# AndroidX +androidx-annotation = "1.7.1" +androidx-core = "1.12.0" + +# JNA +jna = "5.14.0" + +# Linting and Static Analysis +detekt = "1.23.5" +ktlint = "0.50.0" + +# AndroidX Testing +androidx-test-espresso = "3.5.1" +androidx-test-core = "1.5.0" +androidx-test-junit = "1.1.5" +androidx-test-runner = "1.5.2" +androidx-test-work = "2.7.1" + +# Third Party Testing +junit = "4.13.2" +mockito = "5.10.0" +robolectric = "4.11.1" + +# Miscellaneous Gradle plugins +gradle-download-task = "5.5.0" +protobuf-gradle = "0.9.4" +python-envs = "0.0.31" + +[libraries] +# AGP +tools-android-plugin = { group = "com.android.tools.build", name = "gradle", version.ref = "android-plugin" } + +# Google +protobuf = { group = "com.google.protobuf", name = "protobuf-javalite", version.ref = "protobuf" } +protoc = { group = "com.google.protobuf", name = "protoc", version.ref = "protobuf" } + +# Kotlin +kotlin-gradle-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin-compiler" } +kotlinx-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" } + +# Mozilla +mozilla-concept-fetch = { group = "org.mozilla.components", name = "concept-fetch", version.ref = "android-components" } +mozilla-glean = { group = "org.mozilla.telemetry", name = "glean", version.ref = "glean" } +mozilla-glean-gradle-plugin = { group = "org.mozilla.telemetry", name = "glean-gradle-plugin", version.ref = "glean" } +mozilla-glean-native-tests = { group = "org.mozilla.telemetry", name = "glean-native-forUnitTests", version.ref = "glean" } +mozilla-rust-android-gradle = { group = "org.mozilla.rust-android-gradle", name = "plugin", version.ref = "rust-android-gradle" } + +# AndroidX +androidx-annotation = { group = "androidx.annotation", name = "annotation", version.ref = "androidx-annotation" } +androidx-core = { group = "androidx.core", name = "core-ktx", version.ref = "androidx-core" } + +# JNA +jna = { group = "net.java.dev.jna", name = "jna", version.ref = "jna" } + +# Linting and Static Analysis +ktlint = { module = "com.pinterest:ktlint", version.ref = "ktlint" } + +# AndroidX Testing +test-core = { group = "androidx.test", name = "core-ktx", version.ref = "androidx-test-core" } +test-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidx-test-espresso" } +test-junit-ext = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "androidx-test-junit" } +test-runner = { group = "androidx.test", name = "runner", version.ref = "androidx-test-runner" } +test-work = { group = "androidx.work", name = "work-testing", version.ref = "androidx-test-work" } + +# Third Party Testing +junit = { group = "junit", name = "junit", version.ref = "junit" } +mockito = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" } +robolectric = { group = "org.robolectric", name = "robolectric", version.ref = "robolectric" } + +[plugins] +detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } +gradle-download-task = { id = "de.undercouch.download", version.ref = "gradle-download-task" } +gradle-python-envs = { id = "com.jetbrains.python.envs", version.ref = "python-envs" } +kotlin-dsl = { id = "org.gradle.kotlin.kotlin-dsl", version.ref = "kotlin-dsl"} +protobuf-gradle = { id = "com.google.protobuf", version.ref = "protobuf-gradle" } diff --git a/megazords/full/android/build.gradle b/megazords/full/android/build.gradle index 420145086..822ce1807 100644 --- a/megazords/full/android/build.gradle +++ b/megazords/full/android/build.gradle @@ -83,7 +83,12 @@ cargo { } dependencies { - jnaForTest "net.java.dev.jna:jna:$jna_version@jar" + jnaForTest(libs.jna) { + artifact { + extension ="jar" + type = "jar" + } + } } afterEvaluate { diff --git a/publish.gradle b/publish.gradle index b0c65da57..71f5d55b9 100644 --- a/publish.gradle +++ b/publish.gradle @@ -237,12 +237,22 @@ ext.dependsOnTheMegazord = { } } // Depend on the megazord and its support library, as well as the - // above-mentione JNA stuff for testing. + // above-mentioned JNA stuff for testing. dependencies { api project(":full-megazord") implementation project(":native-support") - jnaForTest "net.java.dev.jna:jna:$jna_version@jar" - implementation "net.java.dev.jna:jna:$jna_version@aar" + jnaForTest(libs.jna) { + artifact { + extension ="jar" + type = "jar" + } + } + implementation(libs.jna) { + artifact { + extension ="aar" + type = "aar" + } + } // For reasons unknown, resolving the jnaForTest configuration directly // trips a nasty issue with the Android-Gradle plugin 3.2.1, like `Cannot // change attributes of configuration ':PROJECT:kapt' after it has been diff --git a/tools/nimbus-gradle-plugin/build.gradle b/tools/nimbus-gradle-plugin/build.gradle index 6776edbd2..40e0a547f 100644 --- a/tools/nimbus-gradle-plugin/build.gradle +++ b/tools/nimbus-gradle-plugin/build.gradle @@ -7,7 +7,7 @@ plugins { id 'groovy' id 'maven-publish' id 'groovy-gradle-plugin' - id "org.gradle.kotlin.kotlin-dsl" version "4.2.1" + alias libs.plugins.kotlin.dsl } gradlePlugin {