How to retrieve the LATEST (also SNAPSHOT) version of a maven artifact using aether API? [duplicate]

久未见 提交于 2019-12-07 11:40:41

问题


I'm using eclipse.aether (version 1.0.0.v20140518) to programmatically fetch some maven artifacts from my repository. To do this I am using the following code:

Artifact artifact = new DefaultArtifact( artifactName );
ArtifactRequest artifactRequest = new ArtifactRequest().setArtifact( artifact );
repositorySystem.resolveArtifact(session, artifactRequest);

where artifactName is a String in the format "groupId:artifactId:version". When version is a fixed version (like in "org.myNamespace:myProject:1.0.0") everything works fine. Moreover I should be allowed also to replace the fixed version with "LATEST" (as in "org.myNamespace:myProject:LATEST") and in this case it should load the latest version of that artifact in my repository.

This also works but only partially, meaning that it never retrieves SNAPSHOTs artifacts, but only releases. This doesn't seem to be compliant with maven semantic as it is also described here How do I tell Maven to use the latest version of a dependency?

Am I doing something wrong? Is there a way to load the latest version of an artifact regardless if it is a release or a snapshot?


回答1:


Using an open range (not LATEST) works with resolveVersionRange. For example:

VersionRangeRequest request = new VersionRangeRequest();
request.setArtifact(new DefaultArtifact("groupId", "artifactId", "jar", "(,]"));
VersionRangeResult result = repositorySystem.resolveVersionRange(session, request);
Version highestVersion = result.getHighestVersion();


来源:https://stackoverflow.com/questions/27428068/how-to-retrieve-the-latest-also-snapshot-version-of-a-maven-artifact-using-aet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!