Fall back to anonymous JAR download on 4xx when Maven credentials are rejected#8158
Merged
Conversation
When Maven settings.xml credentials are rejected by the remote repository (401/403), retry the JAR download without authentication. Mirrors `MavenPomDownloader.requestAsAuthenticatedOrAnonymous()` and Apache Maven's behavior, so anonymous-accessible artifacts resolve even when configured credentials are invalid. Also fixes two nits observed during troubleshooting: - local cache filename was missing the hyphen before the classifier (`foo-1.0.0recipes.jar` → `foo-1.0.0-recipes.jar`) - download error message omitted the classifier
2 tasks
Only retry a rejected authenticated JAR download anonymously when the response is a genuine credential rejection, not a transient client error (408 timeout, 425 too early, 429 too many requests). Mirrors MavenPomDownloader.HttpSenderResponseException#isClientSideException(). Also treats configured HTTP-header auth as authentication when deciding whether an anonymous retry is worthwhile.
timtebeek
approved these changes
Jul 2, 2026
timtebeek
left a comment
Member
There was a problem hiding this comment.
Thanks for diving in! I like the idea of splitting up the complexity to land this smaller part first. I've gone ahead and closed my earlier effort already.
Looking over your changes I've applied a few small fixes:
- do not retry for 408 timeouts, 425 or 429 rejected requests
- also retry anonymously when only header auth is present
- swap the evaluation order to check the
intresponse code before the more complex authentication
Let me know if you agree with these changes, and whether you had any further plans before marking this as ready for review or merging.
Approved to merge from my side.
Contributor
Author
|
Changes LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MavenArtifactDownloadernow retries the JAR download anonymously whensettings.xmlcredentials are rejected by the remote repository (4xx), mirroringMavenPomDownloader.requestAsAuthenticatedOrAnonymous(). Credentials are applied first, so existing authenticated downloads against private repositories are unchanged and the anonymous attempt is only a fallback.Fix
LocalMavenArtifactCachecache filename missing the hyphen before the classifier (foo-1.0.0recipes.jar→foo-1.0.0-recipes.jar).Include the classifier in the
MavenDownloadingExceptionmessage so artifact coordinates are complete during troubleshooting.Split from the first commit of Try Maven downloads anonymously first, retry with credentials on 4xx #7447, to land this with minimal risk to existing behavior. A follow-up PR will mirror Apache Maven's anonymous-first behavior.
Test plan
fallsBackToAnonymousWhenServerReturns401fallsBackToAnonymousWhenCredentialsRejecteddownloadDependencies/downloadDependenciesWithClassifier