问题
I am facing a problem with Artifactory v3.9.5 resolving artifacts. I have the following setup:
- local repository called "gradle-snaphot" allowed for snapshots
- virtual repository called "repos" that includes "gradle-snapshot"
- an artifact X uploaded to "gradle-snapshot"
Now, when I try to get the artifact directly, it works fine (credantials passed but omitted here):
wget http://myrepo/artifactory/gradle-snapshot/x/SNAPSHOT/maven-metadata.xml?trace
But when I try to get the artifact via the virtual repository, then it doesn't work:
wget http://myrepo/artifactory/repos/x/SNAPSHOT/maven-metadata.xml?trace
wget output is:
Resolving myrepo... xx.xxx.xxx.xx
Connecting to myrepo|xx.xxx.xxx.xx|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://myrepo/artifactory/repos/x/SNAPSHOT/maven-metadata.xml/ [following]
--2015-12-11 11:17:18-- http://myrepo/artifactory/repos/x/SNAPSHOT/maven-metadata.xml/
Reusing existing connection to myrepo:80.
HTTP request sent, awaiting response... 404 Not Found
2015-12-11 11:17:18 ERROR 404: Not Found.
Artifactory is just returning 302 moved temporarily to the same URL with a slash added like a directory notation. Any idea why accessing virtual repository is not possible this way? In consequence, my Gradle build cannot resolve this dependency.
回答1:
The root cause of this issue is the remote repository pointing at http://mirrors.ibiblio.org/pub/mirrors/maven2.
All requests to this repository will be redirected to http://maven.ibiblio.org/maven2/ no matter which path you are using and more important whether the requested resource exists.
The result is that when requesting an artifact from the virtual repository, at a certain point Artifactory will try to fetch the artifact from this remote repository and will get a 302 answer which redirects to the root of the repository. Artifactory assumes it got the resource it was looking for (got a 200 response code), however the returned resource is a folder and hence the additional / at the end of the URL.
The best solution would be just removing this remote repository and relying on JCenter.
If you do need it, use the http://maven.ibiblio.org/maven2/ URL which will save the redirects.
来源:https://stackoverflow.com/questions/34221284/artifactory-returns-http-302-when-accessing-virtual-repository-url