From 18a6dc9719620da8da901e1b9b809e07a341ce53 Mon Sep 17 00:00:00 2001
From: str4d <str4d@mail.i2p>
Date: Sun, 2 Nov 2014 01:35:55 +0000
Subject: [PATCH] Use mavenLocal() repository instead of a local file repo

---
 README.md                | 17 +++---------
 build.gradle             | 11 --------
 client/build.gradle      | 30 ++++++++-------------
 gradle/maven-push.gradle | 56 +++++++++++++++++++++-------------------
 4 files changed, 45 insertions(+), 69 deletions(-)

diff --git a/README.md b/README.md
index 76c3b8808..8f62628a1 100644
--- a/README.md
+++ b/README.md
@@ -86,24 +86,15 @@ systemProp.socksProxyPort=9150
 
 ## Client library
 
-### "Uploading" to a local file repository (to use a local build of the library in a project)
+### "Uploading" to the local Maven repository (to use a local build of the library in a project)
 
-1. Add the following line to your `~/.gradle/gradle.properties`:
+1. `gradle :client:installArchives`
 
-    ```
-    localFileRepoDir=/path/to/local/file/repo
-    ```
-
-2. `gradle :client:uploadArchives`
-
-3. Add the resulting directory to your project as a repository. For Gradle projects, add the following above any existing repositories (so it is checked first):
+2. Add the local Maven repository to your project. For Gradle projects, add the following above any existing repositories (so it is checked first):
 
     ```
     repositories {
-        flatDir {
-            name 'fileRepo'
-            dirs file('/path/to/local/file/repo')
-        }
+        mavenLocal()
     }
     ```
 
diff --git a/build.gradle b/build.gradle
index bb5d6e9f6..68d0388c0 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,17 +8,6 @@ buildscript {
     }
 }
 
-if (hasProperty('localFileRepoDir')) {
-    allprojects {
-        repositories {
-            flatDir {
-                name "fileRepo"
-                dirs file(localFileRepoDir)
-            }
-        }
-    }
-}
-
 allprojects {
     version = VERSION_NAME
     group = GROUP
diff --git a/client/build.gradle b/client/build.gradle
index 244167f59..82844defd 100644
--- a/client/build.gradle
+++ b/client/build.gradle
@@ -45,23 +45,15 @@ android.libraryVariants.all { variant ->
     copyClientLibsTask.mustRunAfter ':routerjars:buildClient'
 }
 
-if (hasProperty('localFileRepoDir')) {
-    uploadArchives {
-        repositories {
-            add project.repositories.fileRepo
-        }
+apply from: "${project.rootDir}/gradle/maven-push.gradle"
+
+// Remove routerjars from dependencies
+afterEvaluate { project ->
+    def deployer = uploadArchives.repositories.mavenDeployer
+    deployer*.pom*.whenConfigured { pom ->
+        pom.setDependencies(pom.dependencies.collect { dep ->
+            if (dep.groupId != 'i2p.android.base' && dep.artifactId != 'routerjars')
+                dep
+        })
     }
-} else {
-    apply from: "${project.rootDir}/gradle/maven-push.gradle"
-
-    // Remove routerjars from dependencies
-    afterEvaluate { project ->
-        def deployer = uploadArchives.repositories.mavenDeployer
-        deployer*.pom*.whenConfigured { pom ->
-            pom.setDependencies(pom.dependencies.collect { dep ->
-                if (dep.groupId != 'i2p.android.base' && dep.artifactId != 'routerjars')
-                    dep
-            })
-        }
-    }
-}
\ No newline at end of file
+}
diff --git a/gradle/maven-push.gradle b/gradle/maven-push.gradle
index cf818c87e..b9b9e3ab7 100644
--- a/gradle/maven-push.gradle
+++ b/gradle/maven-push.gradle
@@ -88,38 +88,42 @@ afterEvaluate { project ->
         }
     }
 
+    task installArchives(type: Upload) {
+        description "Installs the artifacts to the local Maven repository."
+        configuration = configurations['archives']
+        repositories {
+            mavenDeployer {
+                pom.groupId = GROUP
+                pom.artifactId = POM_ARTIFACT_ID
+                pom.version = VERSION_NAME
+
+                repository url: "file://${System.properties['user.home']}/.m2/repository"
+            }
+        }
+    }
+
     signing {
         required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
         sign configurations.archives
     }
 
-    android.libraryVariants.all { variant ->
-        def androidJavadocs = task("android${variant.name.capitalize()}Javadocs", type: Javadoc) {
-            source = variant.javaCompile.source
-            def androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
-
-            classpath = files(variant.javaCompile.classpath.files, androidJar)
-            options {
-                links 'http://docs.oracle.com/javase/6/docs/api/'
-                linksOffline 'http://d.android.com/reference',"${android.sdkDirectory}/docs/reference"
-            }
-            exclude '**/BuildConfig.java'
-            exclude '**/R.java'
-        }
+    task androidJavadocs(type: Javadoc) {
+        source = android.sourceSets.main.java.srcDirs
+        classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
+    }
 
-        def androidJavadocsJar = task("android${variant.name.capitalize()}JavadocsJar", type: Jar, dependsOn: androidJavadocs) {
-            classifier = 'javadoc'
-            from androidJavadocs.destinationDir
-        }
+    task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
+        classifier = 'javadoc'
+        from androidJavadocs.destinationDir
+    }
 
-        def androidSourcesJar = task("android${variant.name.capitalize()}SourcesJar", type: Jar) {
-            classifier = 'sources'
-            from variant.javaCompile.source
-        }
+    task androidSourcesJar(type: Jar) {
+        classifier = 'sources'
+        from android.sourceSets.main.java.sourceFiles
+    }
 
-        artifacts {
-            archives androidSourcesJar
-            archives androidJavadocsJar
-        }
+    artifacts {
+        archives androidSourcesJar
+        archives androidJavadocsJar
     }
-}
\ No newline at end of file
+}
-- 
GitLab