Snapshots from maven local or from nexus repo

We have a CI environment where a build server upload artifacts to a private nexus repo using a snapshot version. When a developer wants to test things the procedure is to first install to the local maven repo and when done commit things and a new snapshot version will generated by the build server. The problem we are having is that once the user has installed an artifact to the local maven repo gradle will never switch back to the never snapshot version available on the nexus repo.

The only way to get this to work is for the user to delete the artifact from the local maven repo. In my understanding should not the latest snapshot version have priority? Is there any tweaking I can do in order to get this behaviour?

What you are seeing is due to the fact, that Gradle caches a changing module (which a SNAPSHOT version is by definition) for 24h. During that time frame remote repositories will not be checked if the artifact has changed. You can control this caching behavior with the help of the resolution strategy. If you want to always check for the latest changing artifact, you can apply the following configuration:

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'hours'

Keep in mind that this has a certain impact on your build performance as the remote repositories have to be checked each time you run the build.

I’m seeing the same behaviour as described by Anders, and the cache timeout does not seem to be the cause of this:

If I install a snapshot artifact (e.g. 0.2-SNAPSHOT) to the local Maven cache and a project with a dependency on this artifact references ‘mavenLocal()’ before any other repository, Gradle seems to always use the artifact found in the local Maven cache - even if the snapshot artifact in another repository is more recent. This happens even if I set the cache timeout for changing modules to, for instance, five seconds.

I assume that this is related to the following sentence in the manual (chapter “How dependency resolution works”):

When the dependency is declared by a static version and a module descriptor file is found in a repository, there is no need to continue searching later repositories and the remainder of the process is short-circuited.

I would also be interested in how to get Gradle to always use the most recent version of a snapshot from any of the referenced repositories.

I just found - it seems like it’s not possible.

1 Like