问题
I went through the documentation and found many useful things. I am currently using apache archiva as a mirror. Downloading the artifacts with maven works fine but I would like to be able to download the artifact using REST api for certain reasons.
For now I can do it by using a direct url to the artifact's download URL which does not seem to be a good way of doing it.
Is there any rest service I missed which would allow me to do the following server:port/restServices/getArtifact/groupId/artifactId/version
回答1:
The REST call is:
GET http://server/restServices/archivaServices/browseService/artifactDownloadInfos/{group}/{artifact}/{version}
The response contains a list of entries whose 'url' key is the link to download the artifact. There's an entry for each downloadable resource, e.g. one for jar, another for pom, etc. The 'type' key can be used to tell which.
Example response:
[
{
"context": "internal",
"url": "http://server/repository/internal/group/artifact/version/artifact-version.jar",
"groupId": "group",
"artifactId": "obs.interfaces",
"repositoryId": "internal",
"version": "version",
"prefix": null,
"goals": null,
"bundleVersion": null,
"bundleSymbolicName": null,
"bundleExportPackage": null,
"bundleExportService": null,
"bundleDescription": null,
"bundleName": null,
"bundleLicense": null,
"bundleDocUrl": null,
"bundleImportPackage": null,
"bundleRequireBundle": null,
"classifier": null,
"packaging": "jar",
"fileExtension": "jar",
"size": "31.78 K",
"type": "jar",
"path": "group/artifact/version/artifact-version.jar",
"id": "artifact-version.jar",
"scope": null
},
{
"context": "internal",
"url": "http://server/repository/internal/group/artifact/version/artifact-version.pom",
"groupId": "group",
"artifactId": "artifact",
"repositoryId": "internal",
"version": "version",
"prefix": null,
"goals": null,
"bundleVersion": null,
"bundleSymbolicName": null,
"bundleExportPackage": null,
"bundleExportService": null,
"bundleDescription": null,
"bundleName": null,
"bundleLicense": null,
"bundleDocUrl": null,
"bundleImportPackage": null,
"bundleRequireBundle": null,
"classifier": null,
"packaging": "pom",
"fileExtension": "pom",
"size": "1.58 K",
"type": "pom",
"path": "group/artifact/version/artifact-version.pom",
"id": "artifact-version.pom",
"scope": null
}
]
Enjoy!
回答2:
You can download artifacts with a get on the Maven url. The returned artifacts from a search should return it to you.
来源:https://stackoverflow.com/questions/19318028/how-do-i-download-programmatically-a-single-artifact-from-apache-archiva-using-r