Gradle Java Hello-World Basic Builds
The Linux/Unix Tutorial shows you Step-by-Step How to Getting-Started with a Gradle Basic Java Hello-World Project.
Gradle Java plugin goes far beyond the basic functionality of source code Compilation and Packaging.
It establishes a Standard Layout for your project and makes sure that the correct tasks are executed for Building a Java project.
Building an Ordinary Java Main Class with Gradle
-
How to Install the Latest Gradle on Linux/Unix.
-
Making the Java Directory Scheme
For Default Gradle use the Maven Build Directories Structure Conventionmkdir -p ~/Documents/gradle/java/myProject
cd ~/Documents/gradle/java/myProject
For the Main Class make:
mkdir -p src/main/java
For the Testing Classes instead:
mkdir -p src/test/java
In Case of a Java Package then Expand the Default Java Directories Structure…
-
Create a simple Java POJO.
nano src/main/java/HelloWorld.class
public class HelloWorld { public static void main(String args[]) { System.out.println("hello, world"); } }
Ctrl+x to Save & Exit from nano Editor :)
-
Making Gradle Java Build File.
nano build.gradle
Append:
apply plugin: 'java'
To Activate the Gradle Java Plugin!
-
Building the Java Project with Gradle.
gradle build
Output like:
:compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :jar :assemble :compileTestJava UP-TO-DATE :processTestResources UP-TO-DATE :testClasses UP-TO-DATE :test :check :build BUILD SUCCESSFUL
-
Running the Java Hello-World Example.
java -cp build/classes/main/ HelloWorld