Their documentation is really slim and I was unable to figure it out.
I found a partial answer here, but it doesn't have all the code.
How can you find the latest version of a maven artifact from Java using aether?
On
This is from the project's Aether Demonstration and Examples site. I didn't try to run it, but it should be your answer.
public static void main( String[] args ) throws Exception
{
System.out.println( "------------------------------------------------------------" );
System.out.println( FindNewestVersion.class.getSimpleName() );
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession( system );
Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-util:[0,)" );
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact( artifact );
rangeRequest.setRepositories( Booter.newRepositories( system, session ) );
VersionRangeResult rangeResult = system.resolveVersionRange( session, rangeRequest );
Version newestVersion = rangeResult.getHighestVersion();
System.out.println( "Newest version " + newestVersion + " from repository "
+ rangeResult.getRepository( newestVersion ) );
}
The Aether Team maintains a demo page with such an example:
FindNewestVersion.Simplified a bit, this is what it comes down to.
Add to your POM the Aether dependencies:
And then, you can use it like such:
This creates a reference to the Maven Central repository and uses the version ranges
[0,)to specify that we're interested in all versions with an unbounded maximal value. Finally, a version range query is performed and that enables us to determine the latest version.