
As part of the [Salesforce Wear Developer Pack for Android Wear][1] I created a Gradle plugin that fetches and deploys Salesforce code (Apex). Gradle is the default build tool for Android but it can also be used with many other languages. For instance, here is an example `build.gradle` file for a project that fetches all of the Apex classes and Visualforce pages:

```groovy
buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath 'com.jamesward:force-gradle-plugin:0.1'
    }
}

apply plugin: 'force'

repositories {
    mavenLocal()
    mavenCentral()
}

force {
    username = forceUsername
    password = forcePassword
    unpackagedComponents = ["ApexPage": "*", "ApexClass": "*"]
}
```

The `unpackagedComponents` definition uses the [Salesforce Metadata Types][2] and pulls everything specified down into the `src/main/salesforce/unpackaged` directory when you run the `forceMetadataFetch` Gradle task. The `forceMetadataDeploy` Gradle task deploys everything in the `src/main/salesforce/unpackaged` directory to Salesforce.

Try this out:

  * [Install Gradle][3]
  * Create a new project directory containing the `build.gradle` above
  * In your project directory create a new file named `gradle.properties` containing your Salesforce username & password:
    ```properties
    forceUsername=foo@bar.com
    forcePassword=password
    ```

  * Fetch your Salesforce Metadata:
    ```bash
    gradle forceMetadataFetch
    ```

  * Make a change and deploy the Metadata:
    ```bash
    gradle forceMetadataDeploy
    ```

For a complete example check out the [Visualforce + AngularJS + Bootstrap][4] project.

All of the code for the Salesforce Gradle Plugin is on GitHub: <https://github.com/jamesward/force-gradle-plugin>

Let me know what you think. Thanks!

 [1]: http://www.jamesward.com/2014/06/12/integrating-clouds-humans-with-salesforce-and-android-wear
 [2]: https://www.salesforce.com/us/developer/docs/api_meta/index_Left.htm#CSHID=meta_quickstart.htm|StartTopic=Content%2Fmeta_quickstart.htm|SkinName=webhelp
 [3]: http://www.gradle.org/downloads
 [4]: https://github.com/jamesward/visualforce-angular-bootstrap/

