问题
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