How do I force Gradle to get the most recent snapshot version of my package?

Viewed 3550

I have a Maven package I've hosted on GitHub package registry.

Whenever I make an update to the package I run mvn deploy to publish the changes, but if I simply run gradle install on the dependent application it doesn't seem to install the latest version of the package (not sure if settings.xml is relevant to this question so I removed it, but it can be seen at the link to my previous question).

I had a similar issue with using the latest snapshot version of the package in another dependent, which was using Maven as the package manager/build tool instead of Gradle. That was resolved by checking a box to "always update snapshots" in Maven settings. I have checked the box in this project as well, but it doesn't seem to resolve the issue now.

What I have tried:

  • Invalidating cache and restarting IntelliJ

  • reimporting all gradle projects

  • deleting the dependency from my build.gradle and then reimporting projects and install, followed by adding it back and reimporting all projects and install

  • running ./gradlew build -x test --refresh-dependencies (test disabled because they were failing)

This is the log after I run gradle install:

4:07:08 PM: Executing task 'install'...

> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :jar SKIPPED
> Task :install

BUILD SUCCESSFUL in 2s
3 actionable tasks: 1 executed, 2 up-to-date
4:07:10 PM: Task execution finished 'install'.

In my build.gradle I use the following syntax for my dependency (under dependencies):

compile('com.companyname:packagename:0.0.3-SNAPSHOT')

and this is what I have under repositories:

maven {
        url "https://maven.pkg.github.com/companyname/packagename"
        credentials {
            username "TaylorBurke"
            password "*****************"
        }
    }

Not sure if it is related, but when I go into my Maven settings to try and update the repository I get this error:

authorization-exception

So there it is, I think I've included everything. Is it a configuration issue with Maven, Gradle, or IntelliJ?

Edit: because it has been suggested to close this question I am pointing out that the link to the other question does not address installing with Gradle, it simply addresses an error after running mvn deploy. I have already deployed the new package successfully and can get the new version from my other application. My problem is specific to gradle install. Even though the accepted answer mentions he had a similar problem using Gradle (but my problem is not with deploying either) he goes on to say that snapshot versions would provide a solution to the problem expressed, and I am already using a snapshot version in this package. That question is clearly quite different and not at all related to mine.

1 Answers

You have tried quite a few things with IntelliJ, but the problem happens when you run the build from the command line (./gradlew build). That should be a good indication that the problem is not with IntelliJ.

By default, Gradle will cache changing dependencies (e.g. SNAPHOST dependencies) for 24 hours. During that time, it will not ask the repository for newer versions. So if you publish a new version under the same name, Gradle might not see it for another day.

Using the --refresh-dependencies option will make Gradle ignore the cache, and thereby download the artifacts again.

You can also change the cache retention period through a ResolutionStrategy. You can also configure it to always check for changed dependencies if you like.

Read more about dynamic dependencies here: https://docs.gradle.org/current/userguide/dynamic_versions.html


If you are curious, the Gradle artifact cache is by default located in $USER_HOME/.gradle/caches/modules-2/files-2.1 (the numbers may be different depending on which version of Gradle you are using). This cache is unrelated to the one you mention in IntelliJ.

Also, the authentication error in the IntelliJ maven repository browser is because your credentials are in the Gradle configuration and not in IntelliJ. So this is also unrelated to Gradle.

Related