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/. */
5 import org.yaml.snakeyaml.Yaml
13 classpath 'org.yaml:snakeyaml:2.2'
17 // Synchronized library configuration for all modules
18 // This "componentsVersion" number is defined in "version.txt" and should follow
19 // semantic versioning (MAJOR.MINOR.PATCH). See https://semver.org/
22 public final String componentsVersion
23 public final String componentsGroupId
24 public final Integer jvmTargetCompatibility
25 public final Integer compileSdkVersion
26 public final Integer minSdkVersion
27 public final Integer targetSdkVersion
30 String componentsVersion,
31 String componentsGroupId,
32 Integer jvmTargetCompatibility,
33 Integer compileSdkVersion,
34 Integer minSdkVersion,
35 Integer targetSdkVersion
37 this.componentsVersion = componentsVersion
38 this.componentsGroupId = componentsGroupId
39 this.jvmTargetCompatibility = jvmTargetCompatibility
40 this.compileSdkVersion = compileSdkVersion
41 this.minSdkVersion = minSdkVersion
42 this.targetSdkVersion = targetSdkVersion
46 def setupProject(name, path, description) {
47 settings.include(":$name")
49 project(":$name").projectDir = new File(rootDir, "../android-components/${path}")
51 // project(...) gives us a skeleton project that we can't set ext.* on
52 gradle.beforeProject { project ->
53 // However, the "afterProject" listener iterates over every project and gives us the actual project
54 // So, once we filter for the project we care about, we can set whatever we want
55 if (project.name == name) {
56 project.ext.description = description
61 // Return a manifest version string that respects the Firefox version format,
62 // see: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/version#version_format
63 def getManifestVersionString(componentsVersion) {
64 // We assume that the `version.txt` file will always contain a version
65 // string with at least two parts separated with a dot. Below, we extract
66 // each part, and we make sure that there is no letter, e.g. `"0a2"` would
68 String[] parts = componentsVersion.split("\\.").collect {
69 part -> part.split("a|b")[0]
71 // Note the single `H` to avoid leading zeros, which are not allowed.
72 String dateAndTime = new Date().format("YYYYMMdd.Hmmss");
74 return "${parts[0]}.${parts[1]}.${dateAndTime}";
78 def buildconfig = yaml.load(new File(rootDir, '../android-components/.buildconfig.yml').newInputStream())
80 buildconfig.projects.each { project ->
81 // If we're building A-C, set up all projects, otherwise exclude samples e.g., if we're building Fenix or Focus.
82 // The samples are not relevant for the Fenix and Focus builds.
83 if (rootDir.toString().contains("android-components") || !project.key.startsWith("samples")) {
84 setupProject(project.key, project.value.path, project.value.description)
88 gradle.projectsLoaded { ->
89 def componentsVersion = new File(rootDir, '../version.txt').text.stripTrailing()
90 def configData = yaml.load(new File(rootDir, '../android-components/.config.yml').newInputStream())
91 String version = componentsVersion
93 if (gradle.rootProject.hasProperty("nightlyVersion")) {
94 version = gradle.rootProject.nightlyVersion
95 } else if (gradle.rootProject.hasProperty("local")) {
96 // To support local auto-publication workflow, we use a version prefix we wouldn't normally encounter.
98 } else if (gradle.hasProperty("localProperties.branchBuild.android-components.version")) {
99 version = gradle.getProperty("localProperties.branchBuild.android-components.version")
102 // Wait until root project is "loaded" before we set "config"
103 // Note that since this is set on "rootProject.ext", it will be "in scope" during the evaluation of all projects'
104 // gradle files. This means that they can just access "config.<value>", and it'll function properly
105 gradle.rootProject.ext.config = new Config(
107 configData.componentsGroupId,
108 configData.jvmTargetCompatibility,
109 configData.compileSdkVersion,
110 configData.minSdkVersion,
111 configData.targetSdkVersion
114 gradle.rootProject.ext.buildConfig = buildconfig
116 // Define a reusable task for updating the version in manifest.json for modules that package
117 // a web extension. We automate this to make sure we never forget to update the version, either
118 // in local development or for releases. In both cases, we want to make sure the latest version
119 // of all extensions (including their latest changes) are installed on first start-up.
120 gradle.rootProject.allprojects {
121 ext.updateExtensionVersion = { task, extDir ->
124 include 'manifest.template.json'
125 rename { 'manifest.json' }
128 def values = ['version': getManifestVersionString(rootProject.ext.config.componentsVersion)]
129 inputs.properties(values)