1

Eclipse Aether doesn't seem to return the correct release when I try to resolve a LATEST version:

val artifact = DefaultArtifact("org.testng:testng:LATEST")
val versionResult = system.resolveVrsion(session, VersionRequest(artifact, repositories, null))
println(versionResult)

produces:

6.9.8 @ maven (https://jcenter.bintray.com/, default, releases+snapshots)

However, 6.9.10 is the latest, and JCenter is reporting it correctly, both in the directory and also in the maven-metadata.xml:

<metadata>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.9.10</version>
  <versioning>
    <latest>6.9.10</latest>
    <release>6.9.10</release>

Why am I getting 6.9.8 instead of 6.9.10?

Cedric Beust
  • 15,480
  • 2
  • 55
  • 55
  • Could you post a [mcve]? Your code is unlikely to work because it has typos to begin with. You need post something that we can test. – Tunaki Mar 24 '16 at 22:00
  • That said, from the top of my head, you should be using `resolveVersionRange` with the artifact `"org.testng:testng:(0,]"` like I showed here http://stackoverflow.com/q/35488167/1743880 – Tunaki Mar 24 '16 at 22:24
  • Ranges are the first thing I tried and they return the same result, 6.9.8 instead of 6.9.10. There are no typos, it's valid Kotlin. The elided code is just boiler plate creation of a context and a session, using default constructors. I don't think they will change much to the outcome. – Cedric Beust Mar 25 '16 at 01:47
  • you do have at least one typo, unless the method is actually called "resolveVrsion" – yole Mar 25 '16 at 07:30

1 Answers1

3

There are two things which might the cause of your problem. First you assume that the magic word LATEST is supported by Aether and if i remember correctly (and looking into the code of Aether it is not supported). This means you should use a version range to get the latest.

Furthermore if you have a version range you need to call resolveVersionRange(...) instead of resolveVersion(..).

    String versionRange = "[0,)";

    Artifact artifact =
        new DefaultArtifact( "org.testng:testng:jar:" + versionRange );
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact( artifact );
    rangeRequest.setRepositories( remoteRepos );

    VersionRangeResult rangeResult = repository.resolveVersionRange( repositorySystemSession, rangeRequest );
    List<Version> versions = rangeResult.getVersions();

The above is a slightly modified version taken from a plugin i wrote. There is also a ctor of DefaultArtifact which contains only the appropriate parameters which might be a better alternative to use instead of concatenating the strings.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Thanks. I actually came upon this method which, you are right, is the correct one. I'm now realizing that there are additional parameters to force the resolution to go remote instead of relying on the local XML metadata. I haven't quite figured everything out yet but I'm on my way. Accepting your answer. – Cedric Beust Mar 25 '16 at 14:58