Bitnami Gradle for Oracle Cloud Infrastructure Classic

Gradle is an open source build automation system. It uses a simple programming language to ease the process of building and testing applications.

Examples

Create a "Hello, world" application

Follow these steps:

  • Create the following build.gradle file:

     task hello {
         doLast {
             println 'Hello world!'
         }
     }
    
  • Execute the following command in the same directory as the file:

     $ gradle -q hello
    

    gradle -q disables Gradle's log messages so, in this case, it will only print out the "Hello world!" text.

Deploy a servlet application with Jetty

Follow these steps:

  • Create or set up the directory for your Gradle and Java files. Assume this directory is named yourapp/.

  • Create a basic build.gradle file:

     apply plugin: 'java'
     apply plugin: 'war'
     apply plugin: 'jetty'
    
     repositories {
       mavenCentral()
     }
    
     dependencies {
       providedCompile 'javax.servlet:servlet-api:2.5'
       runtime 'javax.servlet:jstl:1.1.2'
     }
    
     httpPort=8080
    
  • To use Jetty as the application server, set up the following directory structure for the application. Note that the webapp/ directory is where you will decompress your application's files.

     yourapp
     +-- build.gradle
     +-- src
         +-- main
             +-- webapp
    
  • Decompress the files and run the application:

     $ gradle jettyRun
    
  • Enter the URL http://SERVER-IP:8080/APPNAME/ once the console output indicates that Jetty is running to check if it's working. Remember to replace APPNAME with the your application is configured to work on.

Use Jenkins

Follow these steps:

  • Create or set up the directory for your Gradle and Java files. Assume this directory is named yourapp/.

  • Create a basic build.gradle file:

     apply plugin: 'java'
     apply plugin: 'war'
     apply plugin: 'jetty'
    
     repositories {
       mavenCentral()
     }
    
     dependencies {
       providedCompile 'javax.servlet:servlet-api:2.5'
       runtime 'javax.servlet:jstl:1.1.2'
     }
    
     httpPort=8080
    
  • To use Jetty as the application server, set up the following directory structure for the application. Note that the webapp/ directory is where you will decompress your application's files.

     yourapp
     +-- build.gradle
     +-- src
         +-- main
             +-- webapp
    
  • Download the latest jenkins.war file and extract its contents to the webapp/ directory, as follows:

     $ cd yourapp
     $ wget http://mirrors.jenkins-ci.org/war-stable/latest/jenkins.war
     $ unzip jenkins.war -d ./src/main/webapp
    
  • Start your Jetty server with Gradle (and do this every time you want to start Jenkins):

     $ gradle jettyRun
    
  • Finally, and after the console indicates that Jetty is running at your configured port, check if Jenkins is working at http://SERVER-IP:8080/jenkins/.

Understanding Gradle

If this is the first time you are using Gradle, learn how it works on Gradle's official website.

oracle

Bitnami Documentation