/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ plugins { id 'com.android.library' alias(libs.plugins.dependency.analysis) } android { defaultConfig { def appServicesVersion = ApplicationServicesConfig.version if (gradle.hasProperty("localProperties.branchBuild.application-services.version")) { appServicesVersion = gradle["localProperties.branchBuild.application-services.version"] } buildConfigField("String", "LIBRARY_VERSION", "\"" + config.componentsVersion + "\"") buildConfigField("String", "APPLICATION_SERVICES_VERSION", "\"" + appServicesVersion + "\"") // This uses the version catalog entry, which could differ from the version // Gradle actually resolves if a range or `+` were used in the catalog. buildConfigField("String", "GLEAN_SDK_VERSION", "\"" + libs.versions.glean.get() + "\"") if (gradle.mozconfig.substs.MOZ_INCLUDE_SOURCE_INFO) { buildConfigField("String", "VCS_HASH", "\"" + gradle.mozconfig.source_repo.MOZ_SOURCE_STAMP + "\"") } else { buildConfigField("String", "VCS_HASH", "\"\"") } } buildFeatures { viewBinding = true buildConfig = true } namespace = 'mozilla.components.support.base' } dependencies { api project(":components:concept-base") // We expose the app-compat as API so that consumers get access to the Lifecycle classes automatically api libs.androidx.appcompat implementation project(':components:concept-fetch') implementation libs.androidx.activity implementation libs.androidx.core implementation libs.androidx.lifecycle.viewmodel implementation libs.kotlinx.coroutines testImplementation project(':components:support-test') testImplementation libs.androidx.test.core testImplementation libs.androidx.test.junit testImplementation libs.kotlin.test testImplementation libs.kotlinx.coroutines.test testImplementation libs.robolectric } /** * Generates a "Component" enum listing all published components. */ abstract class GenerateComponentEnum extends DefaultTask { @Input abstract ListProperty getComponents() @OutputDirectory abstract DirectoryProperty getOutputDir() @TaskAction void generate() { def dir = outputDir.get().asFile dir.mkdirs() def content = new StringBuilder() content << "/* This Source Code Form is subject to the terms of the Mozilla Public\n" + " * License, v. 2.0. If a copy of the MPL was not distributed with this\n" + " * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n" content << "package mozilla.components.support.base" << "\n" content << "\n" content << "// Automatically generated file. DO NOT MODIFY" << "\n" content << "\n" content << "enum class Component {" << "\n" content << components.get().collect { name -> " " + name }.join(", \n") content << "\n" content << "}\n" content << "\n" new File(dir, "Component.kt").text = content.toString() } } def publishedComponents = buildConfig.projects.findAll { project -> project.value.publish }.collect { project -> project.key.replaceFirst(/^components:/, "").replace("-", "_").toUpperCase(Locale.US) } def generateComponentEnum = tasks.register("generateComponentEnum", GenerateComponentEnum) { components.set(publishedComponents) } androidComponents { onVariants(selector().all()) { variant -> variant.sources.java.addGeneratedSourceDirectory(generateComponentEnum) { it.outputDir } } } // The variant Sources API wires compilation automatically, but DAGP's source // exploder and the publishing sources jars consume the sources separately. tasks.matching { it.name.startsWith("explodeCodeSource") || it.name in ["sourceReleaseJar", "sourcesJar"] }.configureEach { dependsOn(generateComponentEnum) } apply from: '../../../common-config.gradle' apply from: '../../../publish.gradle' ext.configurePublish(config.componentsGroupId, project.name, project.ext.description)