build java project using gradle

The following two tabs change content below.
Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Latest posts by Prasad Kharkar (see all)

Build tools are essentials nowadays as there are more and more enterprise applications coming up and there is a need that code needs to be compatible with all IDEs. Build tools help us compile and publish projects in easier way. Gradle is such one build tool. This article explains how to build java project using gradle

Build Java Project Using Gradle:

We have seen gradle installation on windows and know how to run gradle command. Now we see how to build java project using gradle. Consider a simple hello world program as below.

When you need to build java project with gradle, gradle searches for classes in src/main/java folder structure.Say we keep the structure under directory called javaproject. So will will put Hello.java under javaproject/src/main/java/com/thejavageek.

Now navigate to javaproject directory and create a file build.gradle.A java plugin needs to be applied to build java project using gradle. Write following in build.gradle

Now open command prompt and run gradle build as below. It should be able to successfully compile java project.

gradle ran successfully

After this you will see classes and build directories created and build java project using gradle in the root directory. You can apply different plugins to generate war files for java web projects. We will see how it can be done in further parts of tutorials.

I hope this explains building java project using gradle

Share Button

Prasad Kharkar

Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

3 thoughts on “build java project using gradle

Leave a Reply

Your email address will not be published. Required fields are marked *