Why does gradle download only a pom file without the correspondent jar?

Hi,

I’m currently working with Gradle and found some curious behavior when downloading the dependencies.

I have some dependencies declared in my build.gradle. The most of them are dependent of some other artifacts. Let’s present the next scenario:

I clean up my $GRADLE_USER_HOME/caches directory, so all dependencies should be downloaded again. I ran my “build” task and saved the output and noticed that sometimes dependencies are being downloaded without the jar file, only the pom file is downloaded. This doesn’t happen for all dependencies, but for a bunch of them, it means that for some dependencies the both the jar and the pom are listed. The project builds successfully and it seems like behavior is not altered, which means that all needed dependencies are present.

Does anyone know what is the criteria to download only a pom file and not the jar file? Does it mean that I can always dispense with the jar file?

Thanks!

you might have that jar already in your local ~/.m2 repository. if gradle finds the jar there it won’t be downloaded again

Hi Rene,

Thanks for taking some time to answer, I appreciate!

I verified deleting my .m2 repository and it has the same behavior. I suspect is not an error since the project is not affected, but I’d like to understand why is it happening.

I believe there are some cases were a pom can define a redirection to another pom. This might be where you are seeing “pom only” downloads. One case might be when a pom declares a parent for defining common dependency information imported by multiple “sub-poms”.

http://maven.apache.org/pom.html#POM_Relationships

How are you determining which artifacts are being downloaded? Are you just relying on the logging output of the build?

One reason that a jar file would not be downloaded is if Gradle found a file with the correct checksum in your local Maven repository.

The best way to check what files are actually ‘retrieved’ by Gradle (whether by download, or reuse, or copy) is to create a task that prints all files for a configuration:

’’‘
task showFiles << {
    configurations.compile.each { println it.name }
}
’’’

From the page you shared I think another option can be the “optional” attribute. I think that the transitive resolution strategy downloads the pom file of an optional dependency, and if this optional dependency isn’t needed, gradle doesn’t downloads the jar file. Do you think that this is a valid assumption?