Gradle Plugin for Cloud Foundry for IBM Blue Mix

IBM came late to the PaaS party. Perhaps it was a tactical choice to avoid Cloud Foundry version one. Their delay allowed the cloud foundry platform to evolve so now, with IBM Blue Mix, we have a quick performing version two of cloud foundry.

To use version one of C/F we had to use command line tools like VMC and CF v5.4.7. For V2, we need more modern command line tools like the recently introduced CF ver. 6 which is written in the GO programming language. It avoids the need for a Ruby programming installation as the GO version of CF carries all it’s own logic as a single bundle. Hurrah ! I use CF v6.0.2 to talk to Blue Mix.

But as i am still looking for better ways to deploy apps to cloud foundry platforms, i like to use a build tool and, as i’ve reported in prior posts, the gradle build tool is my current flavor of the month. With it, we can get plugin components that do much of the work and add new pieces of functionality.

So for my gradle build scripts, i’ve picked up on the cloud foundry plugin for gradle. Scott Frederick explains it in more detail here if you have a need to know.

Back to IBM’s Blue Mix. Here is part of my gradle build script to deploy an app to IBM’s Blue Mix platform. We need to declare the plugin we need and the location where it can be downloaded from, so :


import org.apache.ivy.plugins.resolver.URLResolver
apply plugin: 'cloudfoundry'
buildscript {
 repositories {
 maven { url "" }
 dependencies {
 classpath group: 'org.cloudfoundry', name: 'cf-gradle-plugin', version: '1.0.2'

Notice that i’ve picked v1.0.2 as this version WILL talk to later cloud foundry v2 platforms. To reach  the earlier version one platforms, we use v1.0.0 of this plugin.

Next we need to declare some values inside the closure used by this plugin.  In particular, the target API address needs to be, for your username and password values, put in the ones you used to join IBM’s beta plan for Blue Mix. Or do so here.

Then pick the name your want your app to be. Fill that name into the application field below and repeat it in the URI in place of my caelyftemplate2 choice. The full closure looks like this :

cloudfoundry {
 space = 'dev'
 username = ''
 password = '******'
 file = new File('build/libs/template-project-1.2.0.war')
 uri = ''
 application = 'caelyftemplate2'

and that should do it. I’m deploying a war file from within my gradle build folder. You might need to change the new File(‘xxx’) choice to point to your own war file.

Wrap the above text into a build.gradle text file. You need an installed gradle build tool from

To see what cloud foundry commands we have from the plugin, we can do a ‘tasks’ request to show them. Here is a sample output on my system from such a command:

jim@a1128-uk:/media/jim/project$ bash gradlew -b tasks
 Parallel execution is an incubating feature.
 All tasks runnable from root project
Build Setup tasks
 init - Initializes a new Gradle build. [incubating]
 wrapper - Generates Gradle wrapper files. [incubating]
Cloud Foundry tasks
 cf-app - Displays information about the application deployment
 cf-apps - Lists applications running on the targeted Cloud Foundry platform
 cf-bind - Binds services to an application
 cf-create-service - Creates a service, optionally binding it to an application
 cf-delete - Deletes an application deployment
 cf-delete-service - Deletes a service
 cf-deploy - Deploys a variants of an application
 cf-env - List application environment variables
 cf-login - Logs in to the target Cloud Foundry platform
 cf-logout - Logs out of the target Cloud Foundry platform
 cf-logs - Shows the contents of log files
 cf-map - Maps a URI to an application
 cf-push - Pushes an application
 cf-restart - Restarts an application
 cf-scale - Scales application instances up or down
 cf-service-plans - Displays information about service offerings
 cf-services - Displays information about service instances
 cf-set-env - Sets environment variables to an application
 cf-spaces - Displays available spaces
 cf-start - Starts an application
 cf-stop - Stops an application
 cf-swap-deployed - Swaps the URIs for deployed variants of an application
 cf-target - Displays information about the target Cloud Foundry platform
 cf-unbind - Unbinds services from an application
 cf-undeploy - Undeploys variants of an application
 cf-unmap - Unmaps a URI from application
 cf-unset-env - Deletes environment variables from an application
Help tasks
 dependencies - Displays all dependencies declar
ed in root project 'template-project'.
 dependencyInsight - Displays the insight into a specific dependency in root project 'template-project'.
 help - Displays a help message
 projects - Displays the sub-projects of root project 'template-project'.
 properties - Displays the properties of root project 'template-project'.
 tasks - Displays the tasks runnable from root project 'template-project'.
To see all tasks and more detail, run with --all.


Total time: 31.991 secs

You can see one of the deployment commands. The CF-PUSH task asks gradle to deploy an app to BlueMix.

First, you need to login before running the CF-PUSH command, so do CF-LOGIN which uses your credentials from within the closure.

Make sure you change directories into the folder with the above build.gradle script. Then from a command line, try this:

gradle cf-login cf-push

This command asks the gradle build tool to issue a login to the BlueMix platform at the defined target using the credentials from within the closure. As i’m using Lubuntu Linux 14.04, i need to call the ‘bash’ tool  my command looks like this (apple/windoze people won’t need bash):

jim@a1128-uk:/media/jim/project$ bash gradle -b build.gradle cf-login cf-push
Parallel execution is an incubating feature.
Authenticating to '' with username ''
Authentication successful
Updating application caelyftemplate2
Uploading build/libs/template-project-1.2.0.war
Starting caelyftemplate2
-----> Downloaded app package (34M)
-----> Downloaded app buildpack cache (4.0K)
Buildpack Version: 20140425-1807
-----> Downloading IBM 1.7.0 JRE from (0.0s)
 Expanding JRE to .java (1.1s)
Downloading from output/wlp/ ... (0.0s).
Installing archive ... (0.6s).

-----> Uploading droplet (126M)

Checking status of caelyftemplate2
 1 of 1 instances running (1 running)
Application caelyftemplate2 is available at http://


Total time: 2 mins 58.293 secs

That’s enough for the moment. If i get a mo. i’ll post a small gradle project that has all this in it. Ok now, go forth and hack !  🙂






Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s