Bug 1506601 - Add dependencies to GeckoView's pom file. r=nalexander
authorAgi Sferro <agi@mozilla.com>
Thu, 29 Nov 2018 19:39:11 +0000
changeset 505290 f1b7c5e6291eaf4e44bef5c1385e09c0c096ae64
parent 505289 88f8e61c7b04acfb705448f02851b0c17ca470db
child 505291 fa4a19e4e88bf6cd3e08e8c447b0697b813f4231
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1506601
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1506601 - Add dependencies to GeckoView's pom file. r=nalexander This adds GeckoView dependencies to the Maven pom file by iterating through the "implementation" dependencies and adding them manually to the pom XML. This workaround can be removed when issue [0] is fixed. This also moves the publishing from the old 'maven' plugin to the new 'maven-publishing' see also [1] and [2]. [0]: https://github.com/gradle/gradle/issues/1842 [1]: https://docs.gradle.org/current/userguide/maven_plugin.html [2]: https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven Differential Revision: https://phabricator.services.mozilla.com/D13113
mobile/android/geckoview/build.gradle
mobile/android/gradle.configure
--- a/mobile/android/geckoview/build.gradle
+++ b/mobile/android/geckoview/build.gradle
@@ -283,41 +283,80 @@ android.libraryVariants.all { variant ->
         from files(variant.javaCompile.source)
     }
 }
 
 android.libraryVariants.all { variant ->
     configureLibraryVariantWithJNIWrappers(variant, "Generated")
 }
 
-apply plugin: 'maven'
+apply plugin: 'maven-publish'
+
+version = computeVersionNumber()
+
+publishing {
+    publications {
+        android.libraryVariants.all { variant ->
+            "${variant.name}"(MavenPublication) {
+                pom {
+                    groupId = 'org.mozilla.geckoview'
 
-uploadArchives {
-    repositories.mavenDeployer {
-        pom.groupId = 'org.mozilla.geckoview'
+                    if (mozconfig.substs.MOZ_UPDATE_CHANNEL == 'release') {
+                        // release artifacts don't specify the channel, for the sake of simplicity
+                        artifactId = "geckoview-${mozconfig.substs.ANDROID_CPU_ARCH}"
+                    } else {
+                        artifactId = "geckoview-${mozconfig.substs.MOZ_UPDATE_CHANNEL}-${mozconfig.substs.ANDROID_CPU_ARCH}"
+                    }
+
+                    url = 'https://wiki.mozilla.org/Mobile/GeckoView'
+
+                    licenses {
+                        license {
+                            name = 'The Mozilla Public License, v. 2.0'
+                            url = 'http://mozilla.org/MPL/2.0/'
+                            distribution = 'repo'
+                        }
+                    }
 
-        if (mozconfig.substs.MOZ_UPDATE_CHANNEL == 'release') {
-            // release artifacts don't specify the channel, for the sake of simplicity
-            pom.artifactId = "geckoview-${mozconfig.substs.ANDROID_CPU_ARCH}"
-        } else {
-            pom.artifactId = "geckoview-${mozconfig.substs.MOZ_UPDATE_CHANNEL}-${mozconfig.substs.ANDROID_CPU_ARCH}"
-        }
+                    scm {
+                        connection = 'scm::hg::https://hg.mozilla.org/mozilla-central/'
+                        url = 'https://hg.mozilla.org/mozilla-central/'
+                    }
+
+                    // Unfortunately Gradle does not provide a way to expose dependencies for custom
+                    // project types like Android plugins. So we need to add them manually to the POM
+                    // XML here, or use a plugin that achieves the same (like
+                    // https://github.com/wupdigital/android-maven-publish). We elect to do this
+                    // manually since our dependencies are simple and plugins increase our complexity
+                    // surface. This workaround can be removed after this issue is fixed:
+                    // https://github.com/gradle/gradle/issues/1842
+                    withXml {
+                        def dependenciesNode = asNode().appendNode('dependencies')
 
-        pom.version = computeVersionNumber()
+                        configurations.getByName("implementation").dependencies.each {
+                            def dependencyNode = dependenciesNode.appendNode('dependency')
+                            dependencyNode.appendNode('groupId', it.group)
+                            dependencyNode.appendNode('artifactId', it.name)
+                            dependencyNode.appendNode('version', it.version)
+                        }
+                    }
+                }
 
-        pom.project {
-            licenses {
-                license {
-                    name 'The Mozilla Public License, v. 2.0'
-                    url 'http://mozilla.org/MPL/2.0/'
-                    distribution 'repo'
-                }
+                artifact tasks["bundle${variant.name.capitalize()}"]
+
+                // Javadoc and sources for developer ergononomics.
+                artifact tasks["javadocJar${variant.name.capitalize()}"]
+                artifact tasks["sourcesJar${variant.name.capitalize()}"]
             }
         }
-        repository(url: "file://${project.buildDir}/maven")
+    }
+    repositories {
+        maven {
+            url = "${project.buildDir}/maven"
+        }
     }
 }
 
 // This is all related to the withGeckoBinaries approach; see
 // mobile/android/gradle/with_gecko_binaries.gradle.
 afterEvaluate {
     // The bundle tasks are only present when the particular configuration is
     // being built, so this task might not exist.  (This is due to the way the
@@ -329,24 +368,16 @@ afterEvaluate {
 
     // Remove default configuration, which is the release configuration, when
     // we're actually building withGeckoBinaries.  This makes `gradle install`
     // install the withGeckoBinaries artifacts, not the release artifacts (which
     // are withoutGeckoBinaries and not suitable for distribution.)
     def Configuration archivesConfig = project.getConfigurations().getByName('archives')
     archivesConfig.artifacts.removeAll { it.extension.equals('aar') }
 
-    artifacts {
-        // Instead of default (release) configuration, publish one with Gecko binaries.
-        archives bundleWithGeckoBinariesRelease
-        // Javadoc and sources for developer ergononomics.
-        archives javadocJarWithGeckoBinariesRelease
-        archives sourcesJarWithGeckoBinariesRelease
-    }
-
     // For now, ensure Kotlin is only used in tests.
     android.sourceSets.all { sourceSet ->
         if (sourceSet.name.startsWith('test') || sourceSet.name.startsWith('androidTest')) {
             return
         }
         (sourceSet.java.srcDirs + sourceSet.kotlin.srcDirs).each {
             if (!fileTree(it, { include '**/*.kt' }).empty) {
                 throw new GradleException("Kotlin used in non-test directory ${it.path}")
--- a/mobile/android/gradle.configure
+++ b/mobile/android/gradle.configure
@@ -260,17 +260,17 @@ set_config('GRADLE_ANDROID_FINDBUGS_TASK
 @depends(gradle_android_build_config)
 def gradle_android_archive_geckoview_tasks(build_config):
     '''Gradle tasks run by |mach android archive-geckoview|.'''
     return [
         'geckoview:assemble{geckoview.variant.name}'.format(geckoview=build_config.geckoview),
         'geckoview:assemble{geckoview.variant.name}AndroidTest'.format(geckoview=build_config.geckoview),
         'geckoview_example:assemble{geckoview_example.variant.name}'.format(geckoview_example=build_config.geckoview_example),
         'geckoview_example:assemble{geckoview_example.variant.name}AndroidTest'.format(geckoview_example=build_config.geckoview_example),
-        'geckoview:uploadArchives',
+        'geckoview:publish{geckoview.variant.name}PublicationToMavenRepository'.format(geckoview=build_config.geckoview),
     ]
 
 set_config('GRADLE_ANDROID_ARCHIVE_GECKOVIEW_TASKS', gradle_android_archive_geckoview_tasks)
 
 
 @depends(gradle_android_build_config)
 def gradle_android_archive_coverage_artifacts_tasks(build_config):
     '''Gradle tasks run by |mach android archive-coverage-artifacts|.'''
@@ -324,20 +324,17 @@ set_config('GRADLE_ANDROID_INSTALL_GECKO
 @imports(_from='itertools', _import='ifilterfalse')
 def gradle_android_dependencies_tasks(*tasks):
     '''Gradle tasks run by |mach android dependencies|.'''
     # The union, plus a bit more, of all of the Gradle tasks
     # invoked by the android-* automation jobs.
     def withoutGeckoBinaries(task):
         return task.replace('withGeckoBinaries', 'withoutGeckoBinaries')
 
-    def isUploadArchives(task):
-        return 'uploadArchives' in task
-
-    return list(ifilterfalse(isUploadArchives, imap(withoutGeckoBinaries, chain(*tasks))))
+    return list(imap(withoutGeckoBinaries, chain(*tasks)))
 
 set_config('GRADLE_ANDROID_DEPENDENCIES_TASKS', gradle_android_dependencies_tasks)
 
 
 # Automation uses this to change log levels, not use the daemon, and use
 # offline mode.
 option(env='GRADLE_FLAGS', default='', help='Flags to pass to Gradle.')