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 ...

Get Gradle Effective Implementations Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.