rife2 / bld

Pure java build tool for developers who don't like dealing with build tools
https://rife2.com/bld
Apache License 2.0
231 stars 12 forks source link

Unexpected error downloading SNAPSHOT dependency #9

Closed jwharm closed 11 months ago

jwharm commented 1 year ago

I have two repositories configured, one is jitpack.io and the other is the OSSRH snapshot repository.

repositories = List.of(
        new Repository("https://jitpack.io"),
        new Repository("https://s01.oss.sonatype.org/content/repositories/snapshots/")
);

scope(compile)
        .include(dependency("io.github.jwharm.javagi:gtk:0.7-SNAPSHOT"));

The dependency should download a bunch of other dependencies, from both declared repositories. Running bld download results in an error:

Unexpected error while retrieving artifact for dependency 'io.github.jwharm.javagi:gtk:0.7-SNAPSHOT' from 'https://jitpack.io/io/github/jwharm/javagi/gtk/0.7-SNAPSHOT/maven-metadata.xml'
> Error while reading URL 'https://jitpack.io/io/github/jwharm/javagi/gtk/0.7-SNAPSHOT/maven-metadata.xml.
> Server returned HTTP response code: 401 for URL: https://jitpack.io/io/github/jwharm/javagi/gtk/0.7-SNAPSHOT/maven-metadata.xml

I think the error is thrown here: https://github.com/rife2/bld/blob/main/src/main/java/rife/bld/dependencies/DependencyResolver.java#L363

Because the snapshot artifact is not found in the first repository (jitpack.io), the HTTP GET throws an IOException: Server returned HTTP response code: 401 for URL: ... that is not handled, so it throws an ArtifactRetrievalErrorException which stops the build process.

jwharm commented 1 year ago

A bit more detail: A HTTP 404 response throws a FileNotFoundException but other errors, like the 401 in my case, throw a plain IOException. I don't know why jitpack responds with 401, but if we'd change FileNotFoundException to IOException in line 360 and 409 of DependencyResolver.java, the resolver should treat all HTTP error codes equally.

I can test and submit a PR for this, or is there a specific reason the resolver currently specifically catches FileNotFoundException only?

gbevin commented 11 months ago

I'm sorry, I don't seem to have gotten a notification about this issue and only saw it now.

It seems that the jetpack.io repository needs authentication to be able to retrieve those artifacts, HTTP 401 means it's not authorized. You can provide the login and password to bld in order to get access. An example of how to not include those credentials in your project can be found here: https://github.com/rife2/bld/wiki/Sensitive-and-Common-Data

Hope this helps.