download dependencies 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)

Many times we use a lot of jar files and frameworks in java projects which is not provided in jdk by default. We need to download jars manually and put them in classpath to use them. When we build projects using gradle, we can automate this task. Let us see how to download dependencies using gradle.

Download Dependencies Using Gradle:

We have seen that we need to write a build.gradle file for building projects. It contains all build scripts. We can declare dependencies in build.gradle file using dependencies{} attribute in from which we can download dependencies using gradle. Declare it as below.

Now we have asked to download dependencies using gradle, but how does it know from where it should download it? We need to specify some repository where gradle can find required jars. We can directly use the maven repository. Gradle can make call to maven repository using mavenCentral(). Declare it as below

While building it will download dependencies using gradle from the maven repository. We want to build a java and eclipse project, hence we will put both plugins. Complete build.gradle becomes as below

Note that we are simply specifying group, name and version mentioned for log4J in maven repository using this information, we are ready to download dependencies using gradle. Navigate to your project directory, in my case project is javaproject. 

build gradleYou can see in the logs that project is built successfully. Downloaded dependency is stored in some folder in .gradle directory.

You can create eclipse project and check whether dependency is added successfully or not. It is successful in my case and can see in eclipse project.

I hope this article helped understand how to download dependencies 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.

Leave a Reply

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