You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Karl Heinz Marbaise <kh...@gmx.de> on 2014/07/04 16:19:26 UTC
Question concerning Resolving an artifact within a plugin
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-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Question concerning Resolving an artifact within a plugin
Posted by Karl Heinz Marbaise <kh...@gmx.de>.
I missed on to ask for:
@Component
private RepositorySystem repository;
can't find an equivalent in the evaluation area?
Kind regards
Karl-Heinz Marbaise
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Question concerning Resolving an artifact within a plugin
Posted by Karl Heinz Marbaise <kh...@gmx.de>.
Hi Jason,
> 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.
so this tip brought me into the right direction and now i have working
result. Thanks for that...
Only for one thing I'm not sure about if this is correct or the right
path...
I'm using the following in my plugin
(https://github.com/khmarbaise/uptodate-maven-plugin/blob/master/src/main/java/com/soebes/maven/plugins/uptodate/AbstractUpToDateMojo.java):
/**
* The project's remote repositories to use for the resolution.
*/
@Parameter( defaultValue = "${project.remoteProjectRepositories}" )
private List<RemoteRepository> remoteRepos;
cause i couldn't find an documented equivalent of it...but it seemed to
be working...I know the docs about evaluation:
http://maven.apache.org/ref/3.1.1/maven-core/apidocs/org/apache/maven/plugin/PluginParameterExpressionEvaluator.html
which gives a reference to the project....so does this include the aboce
remoteProjectRepositories ?
Kind regards
Karl-Heinz Marbaise
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Question concerning Resolving an artifact within a plugin
Posted by Jason van Zyl <ja...@takari.io>.
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 <kh...@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-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@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