9

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.

Taylor Burke
  • 424
  • 4
  • 15
  • okay so it seems like now I have the most recent version but I don't know what actually worked and I would still like to understand the Gradle install process better... – Taylor Burke Jul 15 '20 at 00:13
  • 1
    Does this answer your question? [Why am I getting a "401 Unauthorized" error in Maven?](https://stackoverflow.com/questions/24830610/why-am-i-getting-a-401-unauthorized-error-in-maven) – Martin Zeitler Jul 15 '20 at 01:41
  • 1
    Doesn't seem to be related – Taylor Burke Jul 15 '20 at 01:47
  • I did find another question related to this one however https://stackoverflow.com/questions/32652738/how-can-i-force-update-all-the-snapshot-gradle-dependencies-in-intellij – Taylor Burke Jul 15 '20 at 14:41
  • It is exactly the same error message; even if you can fetch the package, while not being able to login, you'd likely are not going to publish it. – Martin Zeitler Jul 17 '20 at 00:40
  • I haven't had a problem publishing it using Maven – Taylor Burke Jul 17 '20 at 00:57

1 Answers1

11

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.

Bjørn Vester
  • 6,851
  • 1
  • 20
  • 20