How can I retrieve a snapshot if I don’t know the exact filename?

  Uncategorized

. Nexus Provides a separate REST API to retrieve files when interpreting the maven-metadata.xml is required. The syntax looks like this:

wget "http://repository.sonatype.org/service/local/artifact/maven/content?r=snapshots&g=org.sonatype.nexus&a=nexus-utils&v=LATEST" --content-disposition

Where:

  • r = the id of the repository or group to search (Required)
  • g = the groupId of the file (Required)
  • a = the artifactId of the file (Required)
  • v = the version of the file, this may be “LATEST”, “RELEASE”, a version number like “2.0”, or a snapshot version number like “2.0-SNAPSHOT”. (Required)
  • c = the classifier of the file (Optional)
  • e = the type or extension of the file (Optional)
  • p = packaging (Nexus will resolve known packaging types to the correct extension). (Optional)

If the version is not a concrete version, then Nexus will look in the maven-metadata.xml in the same way Maven does to resolve the version. The filename will be set in the content-disposition header field, so if you are using wget, be sure to use the –content-disposition flag so the filename is correct.

There is an alternate form of the API that uses redirects to work around the content-disposition setting. This form is shown below:

wget "http://repository.sonatype.org/service/local/artifact/maven/redirect?

r=snapshots&g=org.sonatype.nexus&a=nexus-utils&v=LATEST"

Alternative – Use Maven

Alternatively, you can use Maven to retreive a snapshot version. First download it to your local maven repository using the “dependency:get” goal”:

mvn dependency:get -DremoteRepositories=http://localhost:8081/repository/maven-public -DgroupId=org.foo -DartifactId=project -Dversion=1.0.0-SNAPSHOT -Dtransitive=false

Then use the “dependency:copy” goal to move the snapshot from your local repository to wherever you like:

mvn dependency:copy -Dartifact=org.foo:project:1.0.0-SNAPSHOT -DoutputDirectory=/some/output/path

Views: 6

LEAVE A COMMENT

What is the capital of Egypt? ( Cairo )