Book Image

Gradle Effective Implementations Guide - Second Edition

By : Hubert Klein Ikkink
Book Image

Gradle Effective Implementations Guide - Second Edition

By: Hubert Klein Ikkink

Overview of this book

Gradle is a project automation tool that has a wide range of applications. The basic aim of Gradle is to automate a wide variety of tasks performed by software developers, including compiling computer source code to binary code, packaging binary codes, running tests, deploying applications to production systems, and creating documentation. The book will start with the fundamentals of Gradle and introduce you to the tools that will be used in further chapters. You will learn to create and work with Gradle scripts and then see how to use Gradle to build your Java Projects. While building Java application, you will find out about other important topics such as dependency management, publishing artifacts, and integrating the application with other JVM languages such as Scala and Groovy. By the end of this book, you will be able to use Gradle in your daily development. Writing tasks, applying plugins, and creating build logic will be your second nature.
Table of Contents (13 chapters)

Running Java applications


If we want to execute a Java executable from a Gradle build, we have several options. Before we explore these options, we will first create a new Java class with a main() method in our project. We will execute this Java class from our build file.

In the src/main/java/gradle/sample directory, we need to create a new SampleApp.java file. The following code listing shows the contents of the file. We will use our Sample class to print the value of the getWelcomeMessage() method to System.out:

// File: src/main/java/gradle/sample/SampleApp.java 
package gradle.sample; 
 
public class SampleApp { 
 
    public SampleApp() { 
    } 
 
    public static void main(String[] args) { 
        final SampleApp app = new SampleApp(); 
        app.welcomeMessage(); 
    } 
 
    public void welcomeMessage() { 
        final String welcomeMessage = readMessage(); 
        showMessage(welcomeMessage); 
    } 
 
    private String readMessage() { 
        final Sample sample = new Sample...