Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Gradle depdencies to IntelliJ compiler classpath

Given a build.gradle that has dependencies like these:

dependencies {
    compile fileTree(dir: 'myLegacyLibsNotYetConverted/lib', include: '*.jar')
    compile fileTree(dir: 'myOtherLegacyLibsNotYetConverted/lib', include: '*.jar')
    compile 'org.springframework:spring-tx:3.1.2.RELEASE'
    compile 'org.springframework:spring-jms:3.1.2.RELEASE'
    compile 'org.springframework:spring-jdbc:3.1.2.RELEASE'
    (...)

    testCompile "junit:junit:4.11"
    testCompile fileTree(dir: "legacyBuild/test-lib", include: "*.jar")
    (...)

    providedCompile "javax.servlet:servlet-api:2.5"
    providedCompile "javax.servlet.jsp:jsp-api:2.2"
}

What is the easiest/recommended way to add them to the IntelliJ's IDE's classpath so that all my interactive compiler and tests have all the class dependencies they need? Is it possible to sync it every time it changes?

A flexible solution that could work in Eclipse with minor changes would be much appreciated too.

like image 222
Zero Distraction Avatar asked Nov 20 '13 05:11

Zero Distraction


2 Answers

Assuming you've got Gradle plugin installed(Preferences>Plugins>Install JetBrains plugin>Gradle), using IntelliJ 12, just clicking on Refresh Gradle Project should put all dependencies in your classpath.

like image 62
eduardohl Avatar answered Sep 22 '22 12:09

eduardohl


The easiest solution is to use the IDE plugins. IntelliJ 13 (EAP) ships with great out-of-the-box support for Gradle. (I don't recommend to use the IntelliJ 12 JetGradle plugin as it's too limited.) For Eclipse there is the Eclipse Gradle Tooling. Both plugins will resync dependencies at the push of a button.

The other approach is to use the eclipse/idea Gradle plugins and (re)generate IDE project files whenever necessary. This approach is documented in the Gradle User Guide.

like image 39
Peter Niederwieser Avatar answered Sep 24 '22 12:09

Peter Niederwieser