2

IntelliJ occasionally thinks a gradle managed JAR file dependency is empty. No combination of replacing the JAR on disk, synchronizing, restarting, or clearing IntelliJ caches resolves the issue, so I believe it doesn't like something about the JAR file itself.

In the project tree:

enter image description here

As you would expect, imports from the JAR's packages fail.

Yet, the JAR files are not empty, and compilations outside of the IntelliJ tool chain work fine.

Does IntelliJ have some strict requirement about JAR contents, formatting, or encoding which may be causing this?

Chris Betti
  • 2,721
  • 2
  • 27
  • 36
  • Naively judging by their name, those look like managed dependencies (maven or similar). If I'm not mistaking, did you check whether they were correctly transferred to your local repository? Albeit rarely, I had some issues with the repositories and I ended up with invalid jars in my local repo... – Morfic Sep 26 '16 at 12:52
  • Yes, they are managed by gradle (and this is a gradle project in IntelliJ). To rule out a bad download, I manually replaced the files in my project's lib directory with fresh copies from our artifact repository. – Chris Betti Sep 26 '16 at 13:12
  • I'm not _very_ familiar with gradle, but I suppose that just like maven [it downloads the dependencies to a local folder/repo](http://stackoverflow.com/questions/12016681/how-to-change-gradle-download-location) so unless you changed it, you will find them there and not in your lib dir. You should be able to verify this by going to `File` -> `Project structure` -> `Libraries` and selecting one from the list. – Morfic Sep 26 '16 at 13:35
  • Ah, your suggestion points out the issue. The libraries are pointed at the lib/ directory (this is our project's setup), but in the `Project structure` -> `Libraries` view, the *wrong versions* of those libraries are listed. This situation arose after switching from head of development to an older branch. It looks like IntelliJ is caching some gradle dependency info despite running `Invalidate Caches / Restart...`. I'll file a bug! – Chris Betti Sep 26 '16 at 13:44
  • Here is the bug report. As of now it is awaiting feedback from JetBrains: https://youtrack.jetbrains.com/issue/IDEA-161736 – Chris Betti Sep 26 '16 at 14:10

3 Answers3

1

There should not be any issue with your jar file and it must be because you have not imported the jar file into the project, you just have copied it inside. So just right click on it and press "add as library"

  • I left an important detail out of my question. These are gradle managed libraries, and this is a gradle project. Apologies, I am updating the question now. – Chris Betti Sep 26 '16 at 13:16
0

Steps for adding external jars in IntelliJ IDEA:

  • Click File from File menu
  • Project Structure (CTRL + SHIFT + ALT + S on Windows/Linux
  • Select Modules at the left panel
  • Dependencies tab
  • '+' → JARs or directories

By this way, the 'jar' file will be indexed and also become expandable.

See Correct way to add external jars.

Community
  • 1
  • 1
Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
0

Try exit and reload IntelliJ to trigger indexing, if other solutions don't work.

Yao Li
  • 2,071
  • 1
  • 25
  • 24