Some libraries not being downloaded when running gradle idea

Yet another issue going on with gradle idea - the IDEA project it’s creating today is randomly missing dependencies because gradle forgot to download the jar files.

For instance, junit-4.11.jar has been downloaded and referenced correctly. hamcrest-core-1.3.jar has been downloaded and referenced correctly. hamcrest-library-1.3.jar has been referenced in the directory that perhaps it should have been downloaded to, but the jar file isn’t there.

hamcrest-core and hamcrest-library are even referenced from the same block in the dependencies.

  hamcrest: [

So they are always included as a unit and it is completely unclear to me why gradle would download one and not the other.

I tried:

  • Running gradle cleanIdea to wipe the project files before generating them. It generates the same files and still doesn’t download the jar.
  • Deleting the project files manually before generating them. Same result.
  • Deleting the ~/.gradle directory before running it again, waiting the hour for it to download all the jars again. It downloads all the jars except for the one I was trying to get it to download.

Seemingly the .iml file itself is correct but the problem is entirely gradle’s failure to download the jar.

I could possibly try and rationalise its behaviour by saying that it failed to download the jar file or something. That should have caused the build to fail. The build isn’t failing, but who knows, maybe that is just another shit behaviour of this software?

When generating the metadata for the IDE (Eclipse or IDEA), if Gradle can’t resolve a dependency, Gradle doesn’t fail the build. This is so you can at least open the project in the IDE to figure out what’s wrong. If you were doing anything else (build, assemble, compileJava, etc), Gradle would have failed the build.

Running gradle dependencies should resolve all of the dependencies and tell you if any of the dependencies could not be resolved (it’ll say FAILED). It won’t download the jars.

Are you behind a proxy or using an internal mirror of Maven Central/JCenter? I don’t see anything wrong with that dependency that would make it fail to resolve and download.

If you put (assuming hamcrest is added to your compile configuration):

task copy(type: Copy) {
   from configurations.compile
   into "${buildDir}/deps"

And run gradle copy, does it download everything into build/deps?

gradle dependencies certainly completes successfully.

I made a modification to that task, since hamcrest is a test dependency:

task copyTest(type: Copy) {
  from configurations.testCompile
  into "${buildDir}/depsTest"

And yeah, the files both end up in depsTest:

-rw-r--r--   1 x  staff     45024 18 Nov 10:52 hamcrest-core-1.3.jar
-rw-r--r--   1 x  staff     53070 18 Nov 10:52 hamcrest-library-1.3.jar

So I’d assume that in IDEA I could go into the project config and look at the lib being there, but it is still pointing to a path that supposedly doesn’t exist. So maybe I’m looking at an IDEA problem, but this sort of thing never happened when we were still checking in jars. :frowning:

We are certainly using an internal mirror, Artifactory, which supposedly goes back to other repositories if anything is missing from its own ones (which would explain why it took a whole hour to re-download everything after nuking ~/.gradle as well.)

i tried recreating your problem by having broken dependencies and fixing them or by manually duplicating dependencies in the .iml file, but neither way seemed to cause problems. Gradle always regenerated the dependencies in the .iml file.

Are there any duplicate .iml files in the same project that could be pointing to the wrong paths?

The path should be something like $HOME/.gradle/caches/modules-2/files-2.1/[group]/[name]/[version]/[sha]/[jar file]. Since it was able to download the jar files this time, can you tell how the path is wrong in the .iml file?

After regenerating this time, it looks like the path in the .iml file is correct, if I just view the file in a text editor. If I look in the IDEA project structure, it still shows the row as red. It looks like the same file path, but IDEA won’t let me copy from the tree, so I can’t tell if it really is… so maybe this really is just IDEA screwing up. :frowning: