VTUFORUM
Simple tutorial on Gradle - Printable Version

+- VTUFORUM (http://www.vtuforum.com)
+-- Forum: KnowledgeBase (/Forum-KnowledgeBase)
+--- Forum: Concepts and Tutorials (/Forum-Concepts-and-Tutorials)
+--- Thread: Simple tutorial on Gradle (/Thread-Simple-tutorial-on-Gradle)



Simple tutorial on Gradle - Sandeep - 04-07-2015 11:40 PM

Hope so most of you came across this term called "Gradle" if you are Java/ Android developer, it got more popularity since it has been added to the default build script for Android Studio. Am trying to learn for my one of the project so sharing some informatio and code here too..

So basically Gradle is a build script which helps us to build the the application and it is derived from Groovy language so most of the syntax are evolved from Groovy..

Here are doing it on Ubuntu, so first download Gradle on Ubutnu, its simple just enter follwing 3 commands on terminal and hit enter

Quote:sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle

It takes some time once its done check by typing $gradle

Okay so now create a simple java "hello world" project and execute using the gradle build. First create the folder structure as it is defined below

create a home folder called "LearnGradle" and build the follwing structure

LearnGradle
------> src
------------> main
-----------------> com
------------------------> sandeep
-------------------------------> gradleTutorial
----------------------------------------> Main.java
-------------> test

Main.java can be any java file example

Quote:package com.sandeep.gradleTutorial;
import java.util.Arrays;
public class Main
{
public static void main(String[] args)
{
System.out.println("Hello world");
}
}


Now start working with gralde. create a build.gradle file in root folder i.e in LearnGradle in our case and add the following content

Quote:apply plugin: "java"

sourceSets{
main.java.srcDir "src/main"
test.java.srcDir "src/test"
}

jar{
manifest.attributes "Main-class":"com.sandeep.gradleTutorial.Main"
}

After having all this, you are ready to build to gradle, so enter the below command in terminal

Quote:$ gradle build

This will build the project if everything is perfect it shows Build Successful, if there are any error then it will list them or it may shows if any test cases get fail.

This will build your project and create build folder which contains all the libs and class files of your project..

Now you see the output for the project by execturing the .jar file genereted in libs folder like this

$ java -jar /build/libs gradleTutorial.jar

The sample code of this tutorial is attached to this post download and test it

Happy coding Big Grin Big Grin Big Grin


RE: Simple tutorial on Gradle - DeangeloM - 06-30-2017 01:38 PM

Quote:Hope so most of you came across this term called "Gradle"
if you use the Bathmate from https://www.grosseteste.com/bathmate-review-results are Java/ Android developer, it got more popularity since it has
been added to the default build script for Android Studio. Am trying to
learn for my one of the project so sharing some informatio and code
here too..

So basically Gradle is a build script which helps us
to build the the application and it is derived from Groovy language so
most of the syntax are evolved from Groovy..
Thanks so much for the guide Sandeep.