Build Tool Integration
Page last updated: May 13, 2015
This page assumes you are using cf CLI v6 and version 1.1.2 of either the Cloud Foundry Maven plugin or the Cloud Foundry Gradle plugin.
Maven Plugin
The Cloud Foundry Maven plugin allows you to deploy and manage applications with Maven goals. This plugin provides Maven users with access to the core functionality of the Cloud Foundry cf command-line tool.
Basic Configuration
To install the Cloud Foundry Maven plugin, add the cf-maven-plugin
to the <plugins>
section of the pom.xml
file:
<plugins>
<plugin>
<groupId>org.cloudfoundry</groupId>
<artifactId>cf-maven-plugin</artifactId>
<version>1.1.2</version>
</plugin>
</plugins>
This minimal configuration is sufficient to execute many of the Maven goals provided by the plugin, as long as you provide all other necessary configuration information through command-line parameters.
Additional Configuration
Instead of relying on command-line parameters, you can include additional configuration information in the pom.xml
by nesting a <configuration>
section within the cf-maven-plugin section.
Example:
<plugins>
<plugin>
<groupId>org.cloudfoundry</groupId>
<artifactId>cf-maven-plugin</artifactId>
<version>1.1.2</version>
<configuration>
<target>http://api.run.pivotal.io</target>
<org>mycloudfoundry-org</org>
<space>development</space>
<appname>my-app</appname>
<url>my-app.shared-domain.com</url>
<memory>512</memory>
<instances>2</instances>
<env>
<ENV-VAR-NAME>env-var-value</ENV-VAR-NAME>
</env>
<services>
<service>
<name>my-rabbitmq</name>
<label>rabbitmq</label>
<provider>rabbitmq</provider>
<version>n/a</version>
<plan>small_plan</plan>
</service>
</services>
</configuration>
</plugin>
</plugins>
After adding and configuring the plugin you can build and push the application to Cloud Foundry with the following command:
$ mvn clean package cf:push
Security Credentials
While you can include Cloud Foundry security credentials in the pom.xml
file, a more secure method is to store the credentials in the Maven settings.xml
file, using the server XML configuration element (http://maven.apache.org/settings.html#Servers). The default location for this configuration file is ~/.m2/settings.xml
.
To implement this:
Add a server to the servers section of the
settings.xml
file. Include the Cloud Foundry security credentials (username and password) and anID
tag. Thepom.xml
references this ID to access the security credentials.<settings> . . . <servers> . . . <server> <id>cloud-foundry-credentials</id> <username>[email protected]</username> <password>s3cr3t</password> </server> . . . </servers> . . . </settings>
Add a server configuration element referencing the ID to the
pom.xml
file:<plugins> <plugin> <groupId>org.cloudfoundry</groupId> <artifactId>cf-maven-plugin</artifactId> <version>1.1.2</version> <configuration> <server>cloud-foundry-credentials</server> . . . </configuration> </plugin> </plugins>
Command-Line Usage
Key functionality available with the Cloud Foundry Maven plugin:
Maven Goal | Cloud Foundry Command | Syntax |
---|---|---|
cf:login | login -u USERNAME | $ mvn cf:login |
cf:logout | logout | $ mvn cf:logout |
cf:app | app APPNAME | $ mvn cf:app [-Dcf.appname=APPNAME] |
cf:apps | apps | $ mvn cf:apps |
cf:target | api | $ mvn cf:target |
cf:push | push | $ mvn cf:push [-Dcf.appname=APPNAME] [-Dcf.path=PATH] [-Dcf.url=URL] [-Dcf.no-start=BOOLEAN] |
cf:start | start APPNAME | $ mvn cf:start [-Dcf.appname=APPNAME] |
cf:stop | stop APPNAME | $ mvn cf:stop [-Dcf.appname=APPNAME] |
cf:restart | restart APPNAME | $ mvn cf:stop [-Dcf.appname=APPNAME] |
cf:delete | delete APPNAME | $ mvn cf:delete [-Dcf.appname=APPNAME] |
cf:scale | scale APPNAME -i INSTANCES | $ mvn cf:scale [-Dcf.appname=APPNAME] [-Dcf.instances=INTEGER] |
cf:env | env APPNAME | $ mvn cf:env [-Dcf.appname=APPNAME] |
cf:services | services | $ mvn cf:services |
cf:create-services | create-service SERVICE PLAN SERVICE_INSTANCE | $ mvn cf:create-services |
cf:delete-services | delete-service SERVICE_INSTANCE | $ mvn cf:delete-service |
cf:bind-services | bind-service APPNAME SERVICE_INSTANCE | $ mvn cf:bind-services |
cf:unbind-services | unbind-service APPNAME SERVICE_INSTANCE | $ mvn cf:unbind-services |
Gradle Plugin
The Cloud Foundry Gradle plugin allows you to deploy and manage applications with Gradle tasks. This plugin provides Gradle users with access to the core functionality of the Cloud Foundry cf command-line tool.
Basic Configuration
To install the Cloud Foundry Gradle plugin, add the cf-gradle-plugin
as a dependency in the buildscript
section of the build.gradle
file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.cloudfoundry:cf-gradle-plugin:1.1.2'
. . .
}
}
apply plugin: 'cloudfoundry'
This minimal configuration is sufficient to execute many of the Gradle tasks provided by the plugin, as long as you provide all other necessary configuration information through command-line parameters
Additional Configuration
Instead of relying on command-line parameters, you can add additional configuration information to build.gradle
in a cloudfoundry
configuration section:
cloudfoundry {
target = "https://api.run.pivotal.io"
space = "deployment"
file = file("path/to/my/file.war")
uri = "my-app.shared-domain.com"
memory = 512
instances = 1
env = [ "key": "value" ]
serviceInfos {
"my_rabbitmq" {
label = "rabbitmq"
plan = "small_plan"
bind = true
}
}
}
After adding and configuring the plugin you can build and push the application to Cloud Foundry with the following command:
$ gradle clean assemble cfPush
Security Credentials
While you can include Cloud Foundry security credentials in the build.gradle
file, a more secure method is to store the credentials in a gradle.properties
file. This file can be placed in either the project directory or in the ~/.gradle
directory.
To implement this, add cfUsername
and cfPassword
with the Cloud Foundry security credentials parameters to the gradle.properties
file as follows:
[email protected]
cfPassword=examplePassword
(Note there are no quotes around either the username or password.)
Command-Line Usage
Key functionality available with the Cloud Foundry Gradle plugin:
Gradle Task | Cloud Foundry Command | Syntax |
---|---|---|
cfLogin | login -u USERNAME | $ gradle cfLogin |
cfLogout | logout | $ gradle cfLogout |
cfApp | app APPNAME | $ gradle cfApp [-PcfApplication=APPNAME] |
cfApps | apps | $ gradle cfApps |
cfTarget | api | $ gradle cfTarget |
cfPush | push | $ gradle cfPush [-PcfApplication=APPNAME] [-PcfUri=URL] [-PcfStartApp=BOOLEAN] |
cfStart | start APPNAME | $ gradle cfStart [-PcfApplication=APPNAME] |
cfStop | stop APPNAME | $ gradle cfStop [-PcfApplication=APPNAME] |
cfRestart | restart APPNAME | $ gradle cfStop [-PcfApplication=APPNAME] |
cfDelete | delete APPNAME | $ gradle cfDelete [-PcfApplication=APPNAME] |
cfScale | scale APPNAME -i INSTANCES | $ gradle cfScale [-PcfApplication=APPNAME] [-PcfInstances=INTEGER] |
cfEnv | env APPNAME | $ gradle cfEnv [-PcfApplication=APPNAME] |
cfServices | services | $ gradle cfServices |
cfCreateService | create-service SERVICE PLAN SERVICE_INSTANCE | $ gradle cfCreateServices |
cfDeleteServices | delete-service SERVICE_INSTANCE | $ gradle cfDeleteServices |
cfBind | bind-service APPNAME SERVICE_INSTANCE | $ gradle cfBind |
cfUnbind | unbind-service APPNAME SERVICE_INSTANCE | $ gradle cfUnbind |