How to QuicStart Building A Java Project With Gradle on Linux-Unix Easy Guide

March 28, 2015 | By the+gnu+linux+evangelist.

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.

Gradle Java Build Hello-World - Featured

Building an Ordinary Java Main Class with Gradle

  1. How to Install the Latest Gradle on Linux/Unix.

    Gradle Installation Guide
  2. Making the Java Directory Scheme
    For Default Gradle use the Maven Build Directories Structure Convention

    mkdir -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…

  3. 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 :)

  4. Making Gradle Java Build File.

    nano build.gradle


    apply plugin: 'java'

    To Activate the Gradle Java Plugin!

  5. Building the Java Project with Gradle.

    gradle build

    Output like:

    :compileJava UP-TO-DATE
    :processResources UP-TO-DATE
    :classes UP-TO-DATE
    :compileTestJava UP-TO-DATE
    :processTestResources UP-TO-DATE
    :testClasses UP-TO-DATE
  6. Running the Java Hello-World Example.

    java -cp build/classes/main/ HelloWorld

QuickChic Theme • Powered by WordPress