OSS Nexus: how to use the REST API to retrieve the latest version as text

I would like to get the last version name (as text) in order to be able to rename artificial files extracted from Nexus with timestamps.

I create an archive from several archives containing internal jar projects, dependencies, related scripts ... But if the packaged jars are snapshots, the archives end with timestamps when loading. These timestamps replace the extension XXX-SNAPSHOT of the archive, and I can not automate the script to perform some tasks, such as extracting the archive, renaming the directory, creating symbolic links, ...

I did not find anything related to this in the rest of the api documentation. Is there an easy way to do this with the rest of the api or some kind of scripts?

Thanks.

Edit:

From the answer below, I managed to get the latest version of the snapshot using LATEST instead of the version name:

Then, using the script, I can get the basic version.

#!/bin/bash VERSION=`curl --silent "http://redmine.saic.int:8081/nexus/service/local/artifact/maven/resolve?r=snapshots&g=com.g2mobility&a=G2-Modem-Mgr&v=LATEST&c=executable&e=tar.gz" | sed -n 's|<baseVersion>\(.*\)</baseVersion>|\1|p'` VERSION=`echo "$VERSION" | tr -d ' '` echo "Version is $VERSION" 

Thanks!

+7
source share
3 answers

Nexus has the following REST API for describing how Maven modules are resolved:

Example

To get information about the following artifact:

 <groupId>org.cometd.jetty</groupId> <artifactId>cometd-jetty-client</artifactId> <version>1.0-SNAPSHOT</version> 

Use the following REST API:

https://oss.sonatype.org/service/local/artifact/maven/resolve?r=cometd-snapshots&g=org.cometd.jetty&a=cometd-jetty-client&v=1.0-SNAPSHOT&e=jar

Returns the following report:

 <artifact-resolution> <data> <presentLocally>true</presentLocally> <groupId>org.cometd.jetty</groupId> <artifactId>cometd-jetty-client</artifactId> <version>1.0-20090313.100344-2</version> <baseVersion>1.0-SNAPSHOT</baseVersion> <extension>jar</extension> <snapshot>true</snapshot> <snapshotBuildNumber>2</snapshotBuildNumber> <snapshotTimeStamp>1236938624000</snapshotTimeStamp> <sha1>0cbf7163f19bf4586e27632a1f742dd0c0e0036d</sha1> <repositoryPath>/org/cometd/jetty/cometd-jetty-client/1.0-SNAPSHOT/cometd-jetty-client-1.0-20090313.100344-2.jar</repositoryPath> </data> </artifact-resolution> 
+8
source

This was a remote headphone publication, offering an alternative way to build distributions from the contents of the Maven repository:

Ivy is an alternative dependency management client that can be run from as follows:

 java -jar ivy.jar -settings ivysettings.xml -dependency org.cometd.jetty cometd-jetty-client 1.0-SNAPSHOT -retrieve "distrib/[artifact]-[revision](-[classifier]).[ext]" 

The ivy command's retrieve parameter specifies how downloaded files should be stored locally:

 -- distrib |-- cometd-api-1.0-SNAPSHOT.jar |-- cometd-jetty-client-1.0-SNAPSHOT.jar |-- cometd-jetty-client-1.0-SNAPSHOT-javadoc.jar |-- cometd-jetty-client-1.0-SNAPSHOT-sources.jar |-- cometd-jetty-server-1.0-SNAPSHOT.jar |-- jetty-6.1.15.jar |-- jetty-client-6.1.15.jar |-- jetty-sslengine-6.1.15.jar |-- jetty-util5-6.1.15.jar |-- jetty-util-6.1.15.jar `-- servlet-api-2.5-20081211.jar 

It turns out the correct temporary artifact, but the revision number "SNAPSHOT" is saved, which I understand what you are trying to do.

The ivysettings file describes the repositories that will be used when loading artifacts:

 <ivysettings> <settings defaultResolver="repos"/> <resolvers> <chain name="repos"> <ibiblio name="central" m2compatible="true"/> <ibiblio name="cometd-snapshot" root="https://oss.sonatype.org/content/repositories/cometd-snapshots/" m2compatible="true"/> </chain> </resolvers> </ivysettings> 
0
source

The documentation for the Maven Resolve Nexus REST API can be found here: https://maven.java.net/nexus-core-documentation-plugin/core/docs/rest.artifact.maven.resolve.html

0
source

All Articles