Gradle with IntelliJ

I'm working on a project that requires Gradle integration. I've never used Gradle before, but I would like to add a .jar file as an external library. I copy and pasted the file into my main project directory and added it as a library by right clicking on it and choosing "add as library". I also added it to my classpath whenever IntelliJ highlighted any imports as an error. However, when I tried to build my project, I got errors saying "Grade: error: package X does not exist" and "Gradle: error: cannot find symbol class Y", where X and Y are packages and classes in the library. When I open the Gradle tool window and click on the refresh button, all references to the added library become errors, and I have to readd the library to my classpath. Doing this and recompiling still doesn't make it work, though. What do I have to do to get Gradle to accept the new library and to compile it correctly?

2 comments

This is explained in the gradle documentation at http://www.gradle.org/docs/current/userguide/userguide_single.html#sub%3afile_dependencies

If you need a local jar dependency, you should configure it in gradle scripts, e.g.:

dependencies {
    compile files('libs/some_local.jar')
}
0

I see, thank you, everything works fine now.

0

Please sign in to leave a comment.