substitute-local-ac.gradle (2461B)
1 def version = null 2 if (gradle.hasProperty("localProperties.autoPublish.android-components.dir")) { 3 // We're doing local development using the autoPublish system. This automatically rebuilds and 4 // publishes android-components packages whenever the source changes. 5 // This version string will selected the latest build package 6 version = '0.0.1-+' 7 } else if (gradle.hasProperty("localProperties.branchBuild.android-components.version")) { 8 // We're running a branch build. Here the version is set to the git commit id in 9 // local.properties 10 version = gradle.getProperty("localProperties.branchBuild.android-components.version") 11 } else { 12 throw new Exception("substitute-local-appservices.gradle called from unexpected context") 13 } 14 logger.lifecycle("[local-ac] adjusting project to use locally published android-components modules (${version})") 15 16 // Inject mavenLocal repository. This is where we're expected to publish modules. 17 repositories { 18 mavenLocal() 19 } 20 21 configurations.configureEach { config -> 22 if (config.isCanBeResolved()) { 23 config.resolutionStrategy { strategy -> 24 dependencySubstitution { 25 // Linter is broken here and incorrectly suggests to replace 26 // all() with configureEach(), which doesn't exist on DependencySubstitutions. 27 // https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/DependencySubstitutions.html 28 //noinspection ConfigurationAvoidance 29 all { dependency -> 30 if (!(dependency.requested instanceof ModuleComponentSelector)) { 31 // We only care about substituting for a module, not a project. 32 return 33 } 34 35 // For every org.mozilla.components.* module, substitute its version for '+'. 36 // '+' version tells gradle to resolve the latest available version. 37 // As long as 'mavenLocal' is in the repositories list, gradle should pick out 38 // latest published module during dependency resolution phase. 39 def group = dependency.requested.group 40 if (group == 'org.mozilla.components') { 41 def name = dependency.requested.module 42 dependency.useTarget([group: group, name: name, version: version]) 43 } 44 } 45 } 46 } 47 } 48 }