Hi Gradle!

Gradle recognizes that sometimes you need a lot effort and sheer tenacity to perform a successful build, hence the elephant.

Gradle is a build tool and dependency manager for programming projects. It can automate the building, testing, publishing and deployment processes of software projects.

Gradle runs on the JVM but it isn’t limited to building just JVM projects. It also comes packaged with support for building native projects. We must have a Java Development Kit (JDK) installed to use gradle in our projects.(docs.gradle.org › current › userguide › what_is_gradle)

Maven, Ivy and ANT were all based on Xml. Then Gradle was released to allow builds to be described in a different language rather than Xml. It was Groovy. And today we can build Kotlin libraries and applications with Gradle, after Java.

We will use IntelliJ Idea CE (Community Edition). It’s free. (I’m using Ultimate version. You may see some minor differences.)

Click for download : https://www.jetbrains.com/idea/download

Let’s create a new project and see what gradle provides us.

Choose Gradle from the left side menu and ensure that Java is checked also.

Give it a name. When you expand Artifact Coordinates, you will see 3 fields. GroupId, ArtifactId and version. If you develop a gradle project and want to share it with your colleagues in the company or other developers around the world, you should define groupId. You can give it a company domain. And artifactId is your project name.

Now build.gradle file looks like below. As we checked Java when creating our project, it’s been added to plugins scope by default. IntelliJ automatically added JUnit to dependencies. We will write our unit test classes after all, so we will need it.

Let’s add another third party dependency library here. Go to terminal window and run “./gradlew build” command.

Gradlew, gradlew.bat is a shell script and a Windows batch script for executing the build with the Wrapper. You can go ahead and execute the build with the Wrapper without having to install the Gradle runtime. If the project you are working on does not contain those Wrapper files then you’ll need to generate them. It helps us to execute gradle tasks.

Now go ahead to main/java directory under the src folder and create a new Java class as below by command+N shortcut. As we added gson dependency as a third party library before at build.gradle file. We can use it to convert product object to a Json object.

Right click and run Product.main()

Look up to terminal window and you will see some tasks are executed. The latest one is our Product.main() task. It is shown as a Json string as we defined above.

Ok, now go to Tools -> Groovy Console and lets try some groovy codes.

Of course we will run “Hello world” as a traditional programming rule :)

Is it similar to Java or Kotlin :)

Ok click little cutie green arrow to run it and see the result…

There are some definitions we should know about :

Project Object Model : It’s a Java object used by Gradle to build projects.

Project : The most important object in the project object model is Project. Every build.gradle represents a project and a Java object gets build called Project. It’s actually assigned to a reference variable called Project that we can use to run methods ourselves or change properties.

Task : The second most important object in the project object model is Task. Actions are the functions performed by Gradle. Task is a collection of actions and project is a collection of tasks.

We can see all the properties we can set to a project model by running ./gradlew properties command from terminal.

And tasks.. Run ./gradlew tasks

I will try to write more about gradle but that’s all for now.

Stay healthy!

Keep coding :)




Mobile Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

CS371P Fall 2021: Kevin Ngo

The “Invest Like the Best” podcast interview with Eric Vishria of Benchmark Capital was probably…

Demystifying Netdata, a real-time monitoring tool

My Dark Sense of Humor Gets Me in Trouble

5 Key Components of a Successful Enterprise Architecture Function

10 Ways to Speed Up a WordPress Website

N Cs of topic X

Mongo Shell Basics Commands

Add new path

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Firuze Gümüş

Firuze Gümüş

Mobile Developer

More from Medium

Expert: Doctor Consult using Dependency Injection with Huawei Kits (Account, Crash, Identity and…

Dynamic Color Curved Border in layout Android-studio

Android cropping image from camera or gallery

Setting up Google Play Games Services for your Unity Android game