Skip to content

Instantly share code, notes, and snippets.

@scothis
Created February 7, 2012 15:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scothis/1760342 to your computer and use it in GitHub Desktop.
Save scothis/1760342 to your computer and use it in GitHub Desktop.
Quick and dirty Gradle task for deploying Cloud Foundry
buildscript {
repositories {
mavenCentral()
maven { url 'http://maven.springframework.org/milestone' }
}
dependencies {
classpath 'org.cloudfoundry:cloudfoundry-client-lib:0.7.1'
}
}
import org.cloudfoundry.client.lib.CloudApplication
import org.cloudfoundry.client.lib.CloudFoundryClient
task cloudFoundryDeploy {
dependsOn assemble
inputs.dir "$project.buildDir/libs"
doLast {
String target = System.properties['vcap.target']
String email = System.properties['vcap.email']
String passwd = System.properties['vcap.passwd']
if (!(target && email && passwd)) {
throw new GradleException("'vcap.target', 'vcap.email' and 'vcap.passwd' system properties are required for the cloudFoundryDeploy task")
}
String appName = project.name
String url = target.replaceFirst(/^api\./, "${appName}.")
CloudFoundryClient client = new CloudFoundryClient(email, passwd, "http://$target")
client.login()
if (client.getApplications().find { it.name == appName }) {
client.stopApplication(appName)
}
else {
client.createApplication(appName, CloudApplication.SPRING, client.getDefaultApplicationMemory(CloudApplication.SPRING), [url], null);
}
client.uploadApplication(appName, file("$project.buildDir/libs/${project.name}.war"))
client.startApplication(appName)
}
}
@cbeams
Copy link

cbeams commented Feb 8, 2012

Note that there is now a clear path for creating and publishing Gradle plugins to the SpringSource repository (http://repo.springsource.org). Take a look at https://github.com/springsource/gradle-plugins for examples/inspiration if you'd eventually like to turn this gist into a proper plugin.

As of this writing the gradle-plugins project is lacking documentation, but I'm happy to help in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment