Move top of tree to use versioned artifacts

For support lib re-deployment, we use non-unique artifacts which
does not work well with a real artifactory. This CL creates a
new release task that uses unique snapshot artifacts.

I've also changed the top of tree task to use these artifacts
since it is the main task for deployments.

Bug: 36069458
Test: local build
Change-Id: I37317fe5485817727398186a0008c839e9c24607
diff --git a/buildSrc/init.gradle b/buildSrc/init.gradle
index 5149a0a..0cab0eb 100644
--- a/buildSrc/init.gradle
+++ b/buildSrc/init.gradle
@@ -91,7 +91,10 @@
 }
 
 def setupRepoOutAndBuildNumber() {
+    // common support repo folder which works well for prebuilts.
     ext.supportRepoOut = ''
+    // files in artifactoryRepoOut can be safely copied into a real artifactory.
+    ext.artifactoryRepoOut = ''
     ext.buildNumber = Integer.toString(ext.extraVersion)
 
     /*
@@ -121,6 +124,7 @@
         project.buildDir = new File("$project.parent.buildDir/../$project.name/build")
     }
     ext.supportRepoOut = new File(buildDir, 'support_repo')
+    ext.artifactoryRepoOut =  new File(buildDir, 'artifactory_repo')
     ext.testApkDistOut = ext.distDir
     ext.testResultsDistDir = new File(distDir, "host-test-reports")
     ext.docsDir = new File(buildDir, 'javadoc')
@@ -212,7 +216,17 @@
             if (isAndroidLibrary || isJavaLibrary) {
                 // Add library to the aggregate dependency report.
                 task allDeps(type: DependencyReportTask) {}
-
+                // create a release task that produces artifactory friends artifacts
+                // a.k.a. unique versions for snapshots with their maven-metadata files.
+                task artifactoryRelease(type : Upload) {
+                    configuration = configurations.archives
+                    repositories {
+                        mavenDeployer {
+                            repository(url: uri("$rootProject.ext.artifactoryRepoOut"))
+                            setUniqueVersion(true)
+                        }
+                    }
+                }
                 // Create release and separate zip task for library.
                 task release(type: Upload) {
                     configuration = configurations.archives
@@ -240,6 +254,7 @@
                         }
                     }
                 }
+                artifactoryRelease.dependsOn release
 
                 def deployer = release.repositories.mavenDeployer
                 deployer.pom*.whenConfigured { pom ->
@@ -281,6 +296,7 @@
 
                 // Make the mainupload depend on this one.
                 mainUpload.dependsOn release
+                mainUpload.dependsOn artifactoryRelease
             }
         }