Easiest way I know of is using Aether directly:

https://github.com/eclipse/aether-demo/blob/master/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindAvailableVersions.java

This is predicated on their being intact Maven metadata for that particular 
artifact, which is in turn predicated on the deploying system understanding 
Maven metadata. Maven obviously does, but other build systems may not.

The only way to get a definitive list of versions is to use something that is 
produced, and validated, on the server side. Something like the Nexus index. 
The Maven metadata is reasonably decent and is the only thing a client can use 
with a dumb server but can never be absolutely correct.

On Jul 4, 2014, at 10:19 AM, Karl Heinz Marbaise <khmarba...@gmx.de> wrote:

> Hi,
> i have the following code which should resolve an artifact given GAV etc.
> 
> so far so good...
> 
>   /**
>     * The project currently being build.
>     */
>    @Parameter( defaultValue = "${project}" )
>    private MavenProject mavenProject;
> 
>    /**
>     * The current Maven session.
>     */
>    @Parameter( defaultValue = "${session}" )
>    private MavenSession mavenSession;
> 
>    @Component
>    private ArtifactHandler artifactHandler;
> 
>    @Component
>    private RepositorySystem repository;
> 
>    private ArtifactResolutionResult resolve( String groupId, String 
> artifactId, String version, String type )
>        throws InvalidVersionSpecificationException
>    {
>        VersionRange versionRange = VersionRange.createFromVersion( version );
> 
>        Artifact artifact =
>            new DefaultArtifact( groupId, artifactId, versionRange, 
> Artifact.SCOPE_COMPILE, type, null, artifactHandler );
> 
>        ArtifactResolutionRequest request = new ArtifactResolutionRequest();
>        request.setArtifact( artifact )
>            .setResolveRoot( true )
>            .setResolveTransitively( false )
>            .setServers( mavenSession.getRequest().getServers() )
>            .setMirrors( mavenSession.getRequest().getMirrors() )
>            .setProxies( mavenSession.getRequest().getProxies() )
>            .setLocalRepository( mavenSession.getLocalRepository() )
>            .setRemoteRepositories( 
> mavenSession.getRequest().getRemoteRepositories() );
> 
>        return repository.resolve( request );
>    }
> 
> 
> My intention was to get the information if of a given artifact newer versions 
> exist so i thought to use a version range in the above code like this:
> 
> 
> VersionRange versionRange = VersionRange.createFromVersionSpec( "[" + version 
> + ",)");
> 
> which fails...it results in checking with a filename on the filesystem which 
> contains the version range specifier but not does not solving the version 
> range...
> 
> 
> [INFO] Downloading: 
> file:///Users/kama/.m2/repository/junit/junit/[3.8,)/junit-[3.8,)
> 
> 
> The question is: How can i check if a newer version of a given artifact 
> exists?
> 
> I have found the implementations in versions-maven-plugin but they look like 
> an overkill for me for simply check if there are newer versions available or 
> not...There i need a VersionsHelper etc. etc....
> 
> 
> May be someone has a better simpler idea?
> 
> Many thanks in advance.
> 
> Kind regards
> Karl-Heinz Marbaise
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
> For additional commands, e-mail: dev-h...@maven.apache.org
> 

Thanks,

Jason

----------------------------------------------------------
Jason van Zyl
Founder,  Apache Maven
http://twitter.com/jvanzyl
http://twitter.com/takari_io
---------------------------------------------------------

The modern conservative is engaged in one of man's oldest exercises in moral 
philosophy; that is, 
the search for a superior moral justification for selfishness.

 -- John Kenneth Galbraith









Reply via email to