build.gradle (4087B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 apply plugin: 'com.android.library' 6 apply plugin: 'kotlin-android' 7 8 def generatedSrcDir = new File(layout.buildDirectory.get().asFile, "generated/components/src/main/java") 9 10 android { 11 defaultConfig { 12 def appServicesVersion = ApplicationServicesConfig.version 13 if (gradle.hasProperty("localProperties.branchBuild.application-services.version")) { 14 appServicesVersion = gradle["localProperties.branchBuild.application-services.version"] 15 } 16 17 buildConfigField("String", "LIBRARY_VERSION", "\"" + config.componentsVersion + "\"") 18 buildConfigField("String", "APPLICATION_SERVICES_VERSION", "\"" + appServicesVersion + "\"") 19 buildConfigField("String", "GLEAN_SDK_VERSION", "\"" + project.ext.gleanVersion + "\"") 20 if (gradle.mozconfig.substs.MOZ_INCLUDE_SOURCE_INFO) { 21 buildConfigField("String", "VCS_HASH", "\"" + gradle.mozconfig.source_repo.MOZ_SOURCE_STAMP + "\"") 22 } else { 23 buildConfigField("String", "VCS_HASH", "\"\"") 24 } 25 } 26 27 sourceSets { 28 main { 29 java { 30 srcDirs += generatedSrcDir 31 } 32 } 33 } 34 35 buildFeatures { 36 viewBinding = true 37 buildConfig = true 38 } 39 40 namespace = 'mozilla.components.support.base' 41 42 } 43 44 dependencies { 45 api project(":components:concept-base") 46 47 // We expose the app-compat as API so that consumers get access to the Lifecycle classes automatically 48 api libs.androidx.appcompat 49 50 implementation project(':components:concept-fetch') 51 52 implementation libs.androidx.activity 53 implementation libs.androidx.core.ktx 54 implementation libs.androidx.lifecycle.viewmodel 55 implementation libs.kotlinx.coroutines 56 57 testImplementation project(':components:support-test') 58 59 testImplementation libs.androidx.test.core 60 testImplementation libs.androidx.test.junit 61 testImplementation libs.kotlinx.coroutines.test 62 testImplementation libs.robolectric 63 } 64 65 /** 66 * Generates a "Components" enum listing all published components. 67 */ 68 tasks.register("generateComponentEnum") { 69 def buildConfigCache = buildConfig 70 def publishedProjects = buildConfigCache.projects.findAll { project -> 71 project.value.publish 72 } 73 def file = new File(generatedSrcDir, "Component.kt") 74 75 inputs.property("publishedProjects", publishedProjects.collect { project -> 76 project.key + ":" + project.value.publish 77 }.sort()) 78 79 outputs.file(file) 80 81 doLast { 82 generatedSrcDir.mkdirs() 83 84 def content = new StringBuilder() 85 content << "/* This Source Code Form is subject to the terms of the Mozilla Public\n" + 86 " * License, v. 2.0. If a copy of the MPL was not distributed with this\n" + 87 " * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n" 88 89 content << "package mozilla.components.support.base" << "\n" 90 content << "\n" 91 content << "// Automatically generated file. DO NOT MODIFY" << "\n" 92 content << "\n" 93 content << "enum class Component {" << "\n" 94 95 content << publishedProjects.collect { project -> 96 " " + project.key.replaceFirst(/^components:/, "").replace("-", "_").toUpperCase(Locale.US) 97 }.join(", \n") 98 99 content << "\n" 100 content << "}\n" 101 content << "\n" 102 103 file.text = content.toString() 104 } 105 } 106 107 afterEvaluate { 108 tasks.matching { it.name.startsWith("compile") && it.name.endsWith("Kotlin") }.configureEach { 109 dependsOn("generateComponentEnum") 110 } 111 112 tasks.matching { it.name == "sourceReleaseJar" || it.name == "sourcesJar" }.configureEach { 113 dependsOn("generateComponentEnum") 114 } 115 } 116 117 apply from: '../../../common-config.gradle' 118 apply from: '../../../publish.gradle' 119 ext.configurePublish(config.componentsGroupId, project.name, project.ext.description)