0

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 {
    jcentral()
}

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?

Cosa Ya
  • 75
  • 1
  • 4
  • It sounds like you have multiple questions here: 1) Where does gradle put the jars that it downloads (i.e. where is the gradle jar cache located)? and 2) How do you set up a gradle project in Eclipse, such that the jars referenced in build.gradle are available on the Eclipse classpath? – GreenGiant Jun 01 '16 at 23:46
  • Yes, exactly. What I need is indeed the answer to these two questions. – Cosa Ya Jun 02 '16 at 02:21
  • Found out that Gradle places the Spring JARs in (C:\Users\USER\.gradle\caches\modules-2\files-2.1\org.springframework). I guess I just need to move these files into my eclipse project then include them in my path. – Cosa Ya Jun 02 '16 at 06:47

2 Answers2

3

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

allprojects{
    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.

Brandon McKenzie
  • 1,655
  • 11
  • 26
1

If you know where the jars are that you want, then do:

Right-click on project -> Build path -> Configure build path... -> Libraries (tab) -> Add External JARs...

Then select all the jars you want from C:\Users\USER\.gradle\caches\modules-2\files-2.1...

GreenGiant
  • 4,930
  • 1
  • 46
  • 76