Bitnami Gradle

NOTE: Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and Mac OS X) or by clicking the shortcut in the Start Menu under "Start -> Bitnami APPNAME Stack -> Application console" (Windows). Learn more.

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://localhost: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://localhost:8080/jenkins/.

Understanding Gradle

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

NOTE: When running the commands shown on this page, replace the installdir placeholder with the full installation directory for your Bitnami stack.

Using Gradle in graphical user interface (GUI) mode

Gradle also has a graphical user interface mode, which lets you use Gradle interactively. To enable this mode, follow these steps:

  • Execute Gradle with the --gui flag:

    $ gradle --gui
    

    A window will open and it will look like the image below:

    Gradle GUI

  • Click the "Command Line" tab and execute, for instance, the "Hello world" task created in this section, just by entering -q hello. You should see something like this:

    Gradle GUI

How to use the environment that I have installed with Bitnami?

To load the Bitnami stack environment, refer to this page.

To check that the environment is loaded correctly, confirm that the output of the commands below reference your Bitnami installation directory:

$ which java
$ which gradle

To execute Gradle, simply use the correct path, as below:

Windows

$ installdir\gradle\bin\gradle.bat

Linux and Mac OS X

$ installdir/gradle/bin/gradle
nativeInstaller

Bitnami Documentation