5

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?

Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336

3 Answers3

5
compile files('/<ABSOLUTE_PATH>/<DEPENDENCY>.jar')
or
//put jar file in lib directory of project.
compile fileTree(dir: 'lib', includes: ['*.jar']) }
Rohit Verma
  • 457
  • 2
  • 13
  • Thanks so much. I kind of know what to type in. I can't find the file. Should I open it in the IDE? Is it okay to edit it outside the IDE? – Water Cooler v2 Aug 21 '17 at 08:22
  • Editing can be done using any editor. Get into project folder, if build.gradle is not present then create new and it should work fine. – Rohit Verma Aug 21 '17 at 08:26
2

How to add Jar in existing project in Intellij

  1. Goto File->project structure-> Libraries tab -> + sign?
  2. Select Java from the list
  3. Select jar file from file system
  4. Choose apply and ok

How to add dependency in gradle project 1. If your project is gradle project it will have build.gradle in root path of project. 2. Open build.gradle and add it in the dependencies block in required decencies. 3. Make sure that repositories for libraries should be already included. (Usually if library is on mavenCentral then it should be like mavenCentral() )

swapnil
  • 230
  • 3
  • 6
  • Thank you. I thought as much. The only problem is, I can't see how to edit the file inside the IDE. Is there a way? Or should I edit the file outside the IDE? – Water Cooler v2 Aug 21 '17 at 08:27
  • 1
    Thank you so much. If we could, I would mark this answer too as the right one because I found it very helpful. :-) – Water Cooler v2 Aug 21 '17 at 08:31
1

You can also add the directory to the repositories{} and simply add the jar as every other.

repositories {
   flatDir {
       dirs 'path/to/your/dir'
   }
}

then

dependencies {
   compile name: 'yourJar'
}

BTW: If you take it from GitHub it should be published to some repo I presume.

What about this one? Aspose.Cells

LazerBanana
  • 6,865
  • 3
  • 28
  • 47