Declare App Dependencies

Page last updated:

Page last updated:

Cloud Foundry uses the Java buildpack to execute the uploaded JAR file as application package. The Java buildpack will run your application using the main() method of the Main class declared in the build.gradle file.

The dependencies needed for the application are also declared in the build.gradle file and are therefore included in the standalone JAR.

The build.gradle file of your deployed sample app looks something like this:

apply plugin: 'java'

sourceCompatibility = 1.8
version = '1.0'

jar {
    manifest {
        attributes 'Implementation-Title': 'CF Java Sample App',
            'Implementation-Version': version,
            'Main-Class': 'com.swisscom.cloud.cloudfoundry.sampleapp.java.ProductService'
    }
    from {
        (configurations.runtime).collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
    exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.sparkjava:spark-core:2.5'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.8.4'
}

...

The build.gradle file declares both the version of Java that will be used to run your application on Cloud Foundry, as well as the dependencies that should be installed with your application.

To install the required dependencies, simply compile/build your application with:

$ gradle build

...

:compileJava
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build

BUILD SUCCESSFUL

Total time: 6.78 secs
I’ve installed the App dependencies locally
View the source for this page in GitHub