I’m using Gradle 1.1 and I have the following in my build.gradle:
mavenRepo url: "https://repository.jboss.org/nexus/content/groups/public/"
Now, the lombok project exist in mavenCentral and in the nexus repo. When I first get the dependencies I get what I expect (which is the latest version of the jar from mavenCentral). Then, sometimes for no apparent reason the jar from the nexus repository is downloaded, even though the dependency has already been satisfied and even worse, the jar from the nexus repo is an older version. How can I prevent this from happening?
Am I doing something wrong? Any help is appreciated.
First, I’d remove the ‘mavenLocal’ repository unless you explicitly need to consume artifacts that have been locally installed by maven. There is no need to add this for performance reasons: Gradle is smart enough to look in the maven local repository to re-use artifacts. This is probably not the cause of your problems, but it could serve to confuse things.
Second, I imagine that this is happening every 24 hours or so? Gradle caches the resolution of dynamic versions for 24 hours by default, but you can tweak this. By setting this value to “0, ‘seconds’” you may be able to see this behaviour consistently.
Third, try inspecting the gradle log files when running with ‘–debug’. The messages you’re interested in are emitted out of ‘CachingModuleVersionRepository’, so grep for those lines.
Thanks for your answer, and sorry for the late reply.
Changing the resolutionStrategy allowed me to see the problem every time.
We are using a local repository for some artifacts that’s the reason for the mavenLocal, I just removed everything else for the post.
Is there something in particular in the debug output that might help me solve the problem?
I can see clearly where the artifact is being found on mavenCentral, just as it should. But after that I see other entries regarding the same artifact with mavenLocal where it doesn’t find anything (it isn’t supposed to find anything), and then after that it tries the jboss.org repo, it founds an older version of the artifact and downloads it anyway.
To me, it makes sense that it checks all three repos (just in case there’s a newer version in one of them), but I don’t get is why doesn’t it quiet after finding out that the one in jboss is older.
Thanks again for your help.
When you say that Gradle chooses an “older” version, what are the version numbers involved?
mavenCentral retrieves version 0.11.6, jboss.org repo retrieves version 0.11.0. It seems like nothing but it matters in our case. I guess I could set the version specifically in the build file and not use the + sign, but now I’m curious about the problem.
With no forcing or excludes involved, Gradle should be using v0.11.6 over v0.11.0.
Try running ‘gradle dependencies’ and ‘gradle dependencyInsight --dependency lombok’ and see if that sheds some light on why v0.11.0 is being chosen.
If that doesn’t help work it out, send us the output of these commands and we’ll see if we can help. (Use gist)
Thanks for all the help. Here’s the link for gradle dependencies: https://gist.github.com/4515104 If I run it again, I get the same output minus the "Download… " line.
Running gradle dependencyInsight --dependency lombok throws the error that dependencyInsight was not found in the project (I’m using Gradle 1.1).
Thanks once again.
Please try using Gradle 1.3 so you can get the improved reporting that was included in this release.
So I used gradle 1.3.
Here’s the output: https://gist.github.com/4520965
I ran it 2 times. On the first one I had deleted the older version of the artifact (version 0.11.0) leaving the correct one (version 0.11.6).
On the second run both versions are in the hard drive and there’s no mention of the old version. Let me know if there’s some other output that could be helpful.
It looks to me like Gradle is behaving as expected. It’s choosing to use v0.11.6 over v0.11.0 downloaded from jboss. These logs don’t demonstrate any problem to me.
I’ll have to change to the newer version then, which means upgrading some parts of my build file. With the older version it’s not only the pom that gets downloaded but the jar also.
Thanks for all your help on the matter.