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

A. 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"

Altenrative - 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

Have more questions? Submit a request

2 Comments

  • 0
    Avatar
    Mark Strickland Emery

    Hi,

    I've got a file in a nexus-2.13.0-01 Maven2 hosted repo, several different versions loaded up with mvn as 0.0.9, 0.99.0, 1.0.0, 1.0.5, 2.1.0, 2.2.0, 2.2.9 for testing. I noticed that my Puppet class wasn't getting the right version onto the test client. Capturing the URL and using it with wget I see the problem too. How is "LATEST" calculated server side? 1.0.5 isn't it.

    wget 'http://192.168.0.197:8082/nexus/service/local/artifact/maven/redirect?g=com.meltd&a=OMG&v=LATEST&r=maven2-hosted-test&p=jpg&' -O /tmp/OMGTEST.jpg

    --2016-09-15 10:47:46-- http://192.168.0.197:8082/nexus/service/local/artifact/maven/redirect?g=com.meltd&a=OMG&v=LATEST&r=maven2-hosted-test&p=jpg&

    Connecting to 192.168.0.197:8082... connected.

    HTTP request sent, awaiting response... 307 Temporary Redirect

    Location: http://192.168.0.197:8082/nexus/service/local/repositories/maven2-hosted-test/content/com/meltd/OMG/1.0.5/OMG-1.0.5.jpg [following]

    --2016-09-15 10:47:46-- http://192.168.0.197:8082/nexus/service/local/repositories/maven2-hosted-test/content/com/meltd/OMG/1.0.5/OMG-1.0.5.jpg

    Reusing existing connection to 192.168.0.197:8082.

    HTTP request sent, awaiting response... 200 OK

    Length: 104637 (102K) [image/jpeg]

    Saving to: ‘/tmp/OMGTEST.jpg’

    /tmp/OMGTEST.jpg 100%[======================================================================================>] 102.18K --.-KB/s in 0.008s

    2016-09-15 10:47:46 (12.2 MB/s) - ‘/tmp/OMGTEST.jpg’ saved [104637/104637]

    Regards, Mark

  • 0
    Avatar
    Peter Lynch

    Mark:

    The answer is to look in this file: 

    http://192.168.0.197:8082/nexus/service/local/repositories/maven2-hosted-test/content/com/meltd/OMG/maven-metadata.xml

    1.0.5 will be the first version in the versions list.

    Edited by Peter Lynch
Article is closed for comments.
Powered by Zendesk