Cosa Ya Cosa Ya - 11 months ago 74
Java Question

How to download Spring and Hibernate JARs through Gradle

I'm currently using Eclipse with Buildship plugin. I want to download Spring and Hibernate JARs into my gradle project, how do I do this? I placed the following in my build.gradle file for dependencies:

apply plugin: 'java'

dependencies {
compile 'org.springframework:spring-context:4.2.6.RELEASE'

repositories {

jar {
manifest {
attributes 'Main-Class': 'one.MainClass'

Upon running gradle build, it says that the build is successful, and I can run the JAR file produced. I cannot however, find the Spring JARs.

How can I download the Spring jars into my eclipse project so i can add them to the build path?

Answer Source

If you use the Eclipse plugin for Gradle, Gradle can handle adding jars to the Eclipse path for you:

    apply plugin: 'eclipse'

After you include that in your build script, simply run gradle eclipse and it will generate the .settings directory and the .project and .classpath files typical of Eclipse projects, replacing them if they already exist. Run this task and refresh your project in Eclipse anytime you change dependencies.

Alternatively, there is a Gradle plugin for Eclipse in the marketplace that can handle this, so long as you import your project as a gradle project.