Merge "Refactor build.gradle & add artifactory support"
diff --git a/artifactory.gradle b/artifactory.gradle
new file mode 100644
index 0000000..d9f9039
--- /dev/null
+++ b/artifactory.gradle
@@ -0,0 +1,27 @@
+apply plugin: 'maven-publish'
+apply plugin: 'com.jfrog.artifactory'
+
+publishing {
+    publications {
+        mavenJava(MavenPublication) {
+            groupId ddGroup
+            artifactId ddArtifactId
+            version ddVersion
+        }
+    }
+}
+
+artifactory {
+    contextUrl = 'http://oss.jfrog.org/artifactory'
+    publish { // gradle clean artifactoryPublish
+        repository {
+            repoKey = 'oss-snapshot-local'
+            username = bintray_user
+            password = bintray_key
+            maven = true
+        }
+        defaults {
+            publications('mavenJava')
+        }
+    }
+}
diff --git a/build.gradle b/build.gradle
index 6b947c8..2c84ae5 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,22 +1,27 @@
 // If building from command line and you don't have the file local.properties that specifies
 // sdk.dir for the Android SDK path, you can run
 // $ ANDROID_HOME=/path/to/android-sdk gradle build
+// Gradle >= 2.1 required
 buildscript {
     repositories {
         jcenter()
     }
     dependencies {
-        // this requires Gradle 2
         classpath 'com.android.tools.build:gradle:1.0.1'
         classpath 'com.github.dcendents:android-maven-plugin:1.2'
         classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0'
+        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.0.3'
     }
 }
 
-// Requires Grade >= 2.1
 plugins {
     id 'com.jfrog.bintray' version '1.1'
 }
+
+apply from: 'properties.gradle'
+group = ddGroup
+version = ddVersion
+
 apply plugin: 'android-sdk-manager'
 apply plugin: 'com.android.library'
 
@@ -24,16 +29,6 @@
     options.compilerArgs << '-Xlint:deprecation'
 }
 
-def ddArtifactId  = 'droiddriver'
-def ddGroup       = 'io.appium'
-def ddVersion     = '0.9.1-SNAPSHOT'
-def ddWebsite     = 'https://github.com/appium/droiddriver'
-def ddTracker     = 'https://github.com/appium/droiddriver/issues'
-def ddGit         = 'https://github.com/appium/droiddriver.git'
-def ddDescription = 'Android UI testing framework'
-version = ddVersion
-group = ddGroup
-
 android {
     compileSdkVersion 21
     buildToolsVersion '21.1.2'
@@ -64,41 +59,6 @@
     }
 }
 
-apply plugin: 'com.github.dcendents.android-maven'
-
-install {
-    repositories.mavenInstaller {
-        pom {
-            project {
-                packaging 'aar'
-                version = ddVersion
-                groupId = ddGroup
-                artifactId = ddArtifactId
-
-                description = ddDescription
-                url ddWebsite
-
-                licenses {
-                    license {
-                        name 'The Apache Software License, Version 2.0'
-                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
-                    }
-                }
-
-                scm {
-                    connection ddGit
-                    developerConnection ddGit
-                    url ddWebsite
-                }
-
-                issueManagement {
-                    url ddTracker
-                }
-            }
-        }
-    }
-}
-
 task sourcesJar(type: Jar) {
     from android.sourceSets.main.java.srcDirs
     classifier = 'sources'
@@ -126,28 +86,6 @@
     archives sourcesJar
 }
 
-Properties properties = new Properties()
-properties.load(project.rootProject.file('local.properties').newDataInputStream())
-
-bintray {
-    publish = true
-    user = properties.getProperty('bintray.user')
-    key = properties.getProperty('bintray.key')
-
-    configurations = ['archives']
-    pkg {
-        repo = 'maven'
-        userOrg = 'appium'
-        name = "${ddGroup}:${ddArtifactId}"
-        websiteUrl = ddWebsite
-        issueTrackerUrl = ddTracker
-        vcsUrl = ddGit
-        desc = ddDescription
-        licenses = ['The Apache Software License, Version 2.0']
-        publicDownloadNumbers = true
-        version {
-            name = ddVersion
-            desc = ddDescription
-        }
-    }
-}
+apply from: 'maven.gradle'
+apply from: 'jcenter.gradle'
+apply from: 'artifactory.gradle'
diff --git a/jcenter.gradle b/jcenter.gradle
new file mode 100644
index 0000000..84da23f
--- /dev/null
+++ b/jcenter.gradle
@@ -0,0 +1,21 @@
+bintray {
+    publish = true
+    configurations = ['archives']
+    user = bintray_user
+    key = bintray_key
+    pkg {
+        repo = 'maven'
+        userOrg = 'appium'
+        name = "${ddGroup}:${ddArtifactId}"
+        websiteUrl = ddWebsite
+        issueTrackerUrl = ddTracker
+        vcsUrl = ddGit
+        desc = ddDescription
+        licenses = ['The Apache Software License, Version 2.0']
+        publicDownloadNumbers = true
+        version {
+            name = ddVersion
+            desc = ddDescription
+        }
+    }
+}
diff --git a/maven.gradle b/maven.gradle
new file mode 100644
index 0000000..e325de0
--- /dev/null
+++ b/maven.gradle
@@ -0,0 +1,34 @@
+apply plugin: 'com.github.dcendents.android-maven'
+
+install {
+    repositories.mavenInstaller {
+        pom {
+            project {
+                packaging 'aar'
+                version = ddVersion
+                groupId = ddGroup
+                artifactId = ddArtifactId
+
+                description = ddDescription
+                url ddWebsite
+
+                licenses {
+                    license {
+                        name 'The Apache Software License, Version 2.0'
+                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+                    }
+                }
+
+                scm {
+                    connection ddGit
+                    developerConnection ddGit
+                    url ddWebsite
+                }
+
+                issueManagement {
+                    url ddTracker
+                }
+            }
+        }
+    }
+}
diff --git a/properties.gradle b/properties.gradle
new file mode 100644
index 0000000..ac434eb
--- /dev/null
+++ b/properties.gradle
@@ -0,0 +1,13 @@
+Properties properties = new Properties()
+properties.load(project.rootProject.file('local.properties').newDataInputStream())
+
+ext.bintray_user = properties.getProperty('bintray.user')
+ext.bintray_key  = properties.getProperty('bintray.key')
+
+ext.ddArtifactId  = 'droiddriver'
+ext.ddGroup       = 'io.appium'
+ext.ddVersion     = '0.9.1-SNAPSHOT'
+ext.ddWebsite     = 'https://github.com/appium/droiddriver'
+ext.ddTracker     = 'https://github.com/appium/droiddriver/issues'
+ext.ddGit         = 'https://github.com/appium/droiddriver.git'
+ext.ddDescription = 'Android UI testing framework'
diff --git a/releasing_to_jcenter.md b/releasing_to_jcenter.md
index cb6be49..d8321db 100644
--- a/releasing_to_jcenter.md
+++ b/releasing_to_jcenter.md
@@ -12,3 +12,20 @@
 Update the version number in `build.gradle` by modifying the value of `ddVersion`. Official releases should be made only after removing the `-SNAPSHOT` suffix. If the same version number is used as an existing release of droiddriver then jcenter will reject the upload.
 
 `gradle clean bintrayUpload`
+
+# Releasing snapshots to artifactory
+
+Snapshots of DroidDriver are released to `http://oss.jfrog.org/artifactory` in the oss-snapshot-local
+repository.
+
+`gradle clean artifactoryPublish`
+
+Note that resolving the snapshots requires adding the maven repo to the gradle build file:
+
+`maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }`
+
+# Known Issues
+
+- `[buildinfo] Properties file path was not found! (Relevant only for builds running on a CI Server)`
+The missing properties warning can be safely ignored. We're populating the values in Gradle so
+the artifactory plugin doesn't know that they're already set.