How to add a JAR file to an existing gradle project?

Water Cooler v2 picture Water Cooler v2 · Aug 21, 2017 · Viewed 7k times · Source

I have a jar file for Aspose Cells for Java that I want to add to an existing Gradle project in IntelliJ IDEA 2017.2.1.

If I go to View -> Tool Windows -> Gradle, I see the gradle window like so but I don't know what to click. I tried right-clicking on Dependencies but nothing happened. Should I click the + sign? I think not.

enter image description here

How do I do that?

  1. Is it okay to add it the non-gradle way, i.e. by clicking File -> Project Structure -> Dependencies tab -> + sign?

  2. What is the gradle way of doing it? Where do I find the build.gradle file to edit? I could see it a few commits earlier but I am having a hard time finding my way around the IDE. I can see the build.gradle file in Windows explorer. Should I edit it by hand outside of the IDE?

Answer

Rohit Verma picture Rohit Verma · Aug 21, 2017
compile files('/<ABSOLUTE_PATH>/<DEPENDENCY>.jar')
or
//put jar file in lib directory of project.
compile fileTree(dir: 'lib', includes: ['*.jar']) }