Skip to content
UoL CS Notes

Build Tools (Gradle)

COMP122 Labs

Installation

Refer to the installation notes for full install details. In summary, install the gradle package:

$ yay -S gradle

Setting up a Java Gradle Project

This will be following the documentation for setting up a new java project.

  1. Create a new project directory:

     $ mkdir demo
     $ cd demo
    
  2. Make a new gradle project using the step-by-step wizard.

     $ gradle init
    
    • For project type choose application (2).
    • As implementation language chose Java (3).
    • As test framework select “JUnit Jupiter” (4).
    • For the other questions just select the default value.
  3. Several files and a folder hierarchy are created. This includes a simple “Hello World” program.
  4. To test, build and run your code execute in the root of the project:

     $ ./gradlew run
    

    The program is run after the output:

     > Task :run
    

Gradle Tasks

Gradle has has several tasks:

  • To clean the project directory:

      $ ./gradlew clean
    

    This will remove all compiler class files.

  • To compile but not run your project:

      $ ./gradlew compileJava
    

    This will compiler all java source files in app/src/main/java and output the compiler bytecode into app/build/main.

To view additional help run:

$ ./gradlew help