0

I'm wondering if Nexus provides API (I unfortunately didn't find any useful examples) to do such thing. So, in my group id (com.testtools) I got artifact hibi which is versioned in manner - major.minor.patch. Currently in this directory I've got versions:

0.0.5
0.1.2
0.1.4

I know how to get certain version or how get latest stored version (here - snapshot), e.g.:

wget 'http://mynexus.se:8081/nexus/service/local/artifact/maven/content?g=com.testtools&a=hibi&v=LATEST&r=snapshots' --content-disposition

give me hibi-0.1.4. But for this hibi artifact I have to be able to get the latest patch for certain minor version. So how can I get 0.0.5 if I pass 0.0 (or 0.1.4 if I pass 0.1)? Tried something like:

wget 'http://mynexus.se:8081/nexus/service/local/artifact/maven/content?g=com.testtools&a=hibi&v=0.1.*&r=snapshots' --content-disposition

but it isn't work properly (artifact not found). I'll be glad for any suggestions.

oundru87
  • 43
  • 1
  • 8
  • Do you need to use wget? The maven-depency-plugin supports version ranges, but AFAIK you can't use them directly in the Nexus urls. – Steven Pessall Mar 11 '14 at 10:03
  • I've just read about ranges and tried - e.g. [0.1.0, 0.2.0) - it in Nexus url, but yep - item not found. I don't need to use wget, what's your suggestion? – oundru87 Mar 11 '14 at 10:36
  • of course, IF it couldn't be done with Nexus magic, I can implement (e.g. in Python) some workaround with parsing the artifact directory and just taking what I want.. but I want to check smarter/more efficient ideas first ;) – oundru87 Mar 11 '14 at 10:42
  • Well, the obvious solution would be to use a maven build. – Steven Pessall Mar 11 '14 at 10:49
  • but if I specified build range [0.1.0, 0.2.0), have I got latest 0.1.x version? Or is it more complicated? – oundru87 Mar 11 '14 at 10:56
  • The round bracket after 0.2.0 indicates that it is exclusive, so the range should do exactly what you need. – Steven Pessall Mar 11 '14 at 11:00
  • 1
    possible duplicate of [Using the Nexus rest API to get latest artifact version for given groupid/artficatid](http://stackoverflow.com/questions/7911620/using-the-nexus-rest-api-to-get-latest-artifact-version-for-given-groupid-artfic) and another example: http://stackoverflow.com/questions/9280447/how-do-i-provide-url-access-to-the-latest-snapshot-of-an-artifact-in-nexus/9284542#9284542 – Mark O'Connor Mar 11 '14 at 19:35
  • @MarkO'Connor, unfortunately changing to 'redirect' also don't provide me to download last patch for minor version (ranges don't work here) – oundru87 Mar 12 '14 at 10:16
  • @StevenPessall I've checked maven possibilities, and dependency:get seems to be the best choice for downloading. Unfortunately it doesn't handle version ranges neither :/ What should I do, - it seems that I need additional pom for this.. – oundru87 Mar 12 '14 at 10:19

1 Answers1

1

Here is a simple pom.xml, which will copy its dependencies (I used slf4j as an example) to the directory "destination". Just start it with "mvn clean install".

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>YourGroup</groupId>
<artifactId>Test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>[1.6.0,1.7.0)</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.8</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>destination</outputDirectory>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <configuration>
                    <allowSnapshots>true</allowSnapshots>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
</project>
Steven Pessall
  • 983
  • 5
  • 15
  • Thank you @Steven! Build of this POM works properly with ranges. But still I've got a small issue when I am trying to download snapshot versions - Maven sees them on Nexus, but consider as invalid, which ends up with failed goals execution with "Could not find artifact" message. These snapshots are locked on Nexus, so I've tried to mvn versions:unlock-snapshots first, but it didn't help. What am I doing wrong here? – oundru87 Mar 12 '14 at 13:50
  • I added a configuration block for the versions-maven-plugin in the example to allow Snapshots. – Steven Pessall Mar 12 '14 at 16:03
  • Thanks. Unfortunately it doesn't work neither.. I've tried also some other things with plugins and more, - e.g. using profiles to overwrite (default repo/snapshot_repo settings) in settings.xml, but still nothing. Found some bugs reported on ranges functionality in Maven, and it seems to have few major problems with them. Nevertheless, I will fit up to this one which works, and will always take the latest release/snapshot for range [1.x.0,1x+1.0) - it should be enough in my case. Thank you again for answer :) – oundru87 Mar 13 '14 at 09:59