How-to QuicStart Building a Java Project with Gradle on Linux-Unix Easy Guide

March 28th, 2015 by thelinuxevangelist

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

    Append:

    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
    :jar
    :assemble
    :compileTestJava UP-TO-DATE
    :processTestResources UP-TO-DATE
    :testClasses UP-TO-DATE
    :test
    :check
    :build
    BUILD SUCCESSFUL
    
  6. Running the Java Hello-World Example

    java -cp build/classes/main/ HelloWorld
Share on Tumblr

Tags: , , , , , , , , , , , , , , , , ,


Comments are disabled