You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by William Ferguson <wi...@xandar.com.au> on 2014/06/19 00:01:52 UTC

Resolving the dependencies for an Artifact

I asked on maven-users but didn't get any viable responses. So I'm hoping
someone here can help.

--------------------------
I have a Mojo that needs to work with Maven 3.0.* and 3.1+

In the Mojo I have an Artifact and I need to resolve it's dependencies. How
can/should I do it?

If I can resolve the Artifact to a MavenProject then I can use
DependencyGraphBuilder (from maven-dependency-tree) to construct a graph of
the deps. But I'm struggling to make the Artifact to MavenProject
conversion happen.

I thought that If I could get a URL to the Artifact's POM file then I could
use DefaultMavenRuntime (maven-runtime) to resolve the URL into a
MavenProject. But

   1. I can't work out how to get a URL to the artifact's POM file (it
   needs to handle both reactor artifacts and repo artifacts)
   2. Even with a URL to the POM file, MavenRuntime#getProject) is
   returning null.

Can someone please point me in the right direction?
Am I even on the right path or is there a much more straight forward way of
getting the dependencies for the Artifact?
--------------------------

William

Re: Resolving the dependencies for an Artifact

Posted by Hervé BOUTEMY <he...@free.fr>.
3 hints:

1. read Dan's explanations
/> If you set “setResolveTransitively(true)” then the/
/> ArtifactResolutionResponse would have all the deps available in it./

2. try Dan's code: it's pretty straightforward

3. explain what you want to see more than this code (which set everything to let 
code downlaod anything, then asks resolver to resolve)

Le vendredi 20 juin 2014 18:56:33 William Ferguson a écrit :
> OK, so it will resolve from the reactor.
> 
> But is the ArtifactResolutionResult going to contain the dependencies of
> the Artifact that I resolve?
> 
> 
> On Fri, Jun 20, 2014 at 6:46 PM, Hervé BOUTEMY <he...@free.fr>
> 
> wrote:
> > Le vendredi 20 juin 2014 08:36:46 William Ferguson a écrit :
> > > Hi Dan,
> > > 
> > > if the ArtifactResolutionResult contains the deps for the Artifact in
> > > the
> > > request then that's exactly what I want. However I can't see that it
> > 
> > does.
> > 
> > > What am I missing?
> > > 
> > > NB the resolution also needs to be able to resolve Artifacts in the
> > > reactor. I'm pretty certain that
> > > 
> > > @Component
> > > 
> > >     private org.apache.maven.repository.RepositorySystem repository;
> > > 
> > > is only going to resolve from the local repo, not the reactor, right?
> > 
> > wrong, I already:
> > - explained it
> > - updated maven-dependency-tree javadoc to keep track of explanations [1]
> > - updated the reactor IT to prove that it runs as expected (ie not
> > resolved
> > before compile, but resolved after compile)
> > 
> > Regards,
> > 
> > Hervé
> > 
> > [1]
> > http://maven.apache.org/shared-archives/maven-dependency-tree-LATEST/apido
> > 
cs/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.html> 
> > > William
> > > 
> > > On Fri, Jun 20, 2014 at 4:58 AM, Daniel Kulp <dk...@apache.org> wrote:
> > > > For Aries, I ended up doing:
> > > >     @Component
> > > >     private org.apache.maven.repository.RepositorySystem repository;
> > > >     
> > > >     private File resolve(String artifactDescriptor) {
> > > >     
> > > >         String[] s = artifactDescriptor.split(":");
> > > >         
> > > >         String type = (s.length >= 4 ? s[3] : "jar");
> > > >         Artifact artifact = repository.createArtifact(s[0], s[1],
> > > >         s[2],
> > > > 
> > > > type);
> > > > 
> > > >         ArtifactResolutionRequest request = new
> > > > 
> > > > ArtifactResolutionRequest();
> > > > 
> > > >         request.setArtifact(artifact);
> > > >         
> > > >         request.setResolveRoot(true).setResolveTransitively(false);
> > > >         request.setServers( session.getRequest().getServers() );
> > > >         request.setMirrors( session.getRequest().getMirrors() );
> > > >         request.setProxies( session.getRequest().getProxies() );
> > > >         request.setLocalRepository(session.getLocalRepository());
> > 
> > 
request.setRemoteRepositories(session.getRequest().getRemoteRepositories()
> > 
> > > > );>
> > > > 
> > > >         repository.resolve(request);
> > > >         return artifact.getFile();
> > > >     
> > > >     }
> > > > 
> > > > If you set “setResolveTransitively(true)” then the
> > > > ArtifactResolutionResponse would have all the deps available in it.
> > > > 
> > > > That seems to work for both Maven 3.0 and 3.1/3.2.
> > > > 
> > > > Dan
> > > > 
> > > > 
> > > > Op Thu, 19 Jun 2014 00:01:52 +0200 schreef William Ferguson <
> > > > 
> > > > william.ferguson@xandar.com.au>:
> > > > > I asked on maven-users but didn't get any viable responses. So I'm
> > > > > hoping
> > > > > someone here can help.
> > > > > 
> > > > > --------------------------
> > > > > I have a Mojo that needs to work with Maven 3.0.* and 3.1+
> > > > > 
> > > > > In the Mojo I have an Artifact and I need to resolve it's
> > 
> > dependencies.
> > 
> > > > How
> > > > 
> > > > > can/should I do it?
> > > > > 
> > > > > If I can resolve the Artifact to a MavenProject then I can use
> > > > > DependencyGraphBuilder (from maven-dependency-tree) to construct a
> > 
> > graph
> > 
> > > > of
> > > > 
> > > > > the deps. But I'm struggling to make the Artifact to MavenProject
> > > > > conversion happen.
> > > > > 
> > > > > I thought that If I could get a URL to the Artifact's POM file then
> > > > > I

Re: Resolving the dependencies for an Artifact

Posted by William Ferguson <wi...@xandar.com.au>.
OK, so it will resolve from the reactor.

But is the ArtifactResolutionResult going to contain the dependencies of
the Artifact that I resolve?


On Fri, Jun 20, 2014 at 6:46 PM, Hervé BOUTEMY <he...@free.fr>
wrote:

> Le vendredi 20 juin 2014 08:36:46 William Ferguson a écrit :
> > Hi Dan,
> >
> > if the ArtifactResolutionResult contains the deps for the Artifact in the
> > request then that's exactly what I want. However I can't see that it
> does.
> > What am I missing?
> >
> > NB the resolution also needs to be able to resolve Artifacts in the
> > reactor. I'm pretty certain that
> >
> > @Component
> >     private org.apache.maven.repository.RepositorySystem repository;
> >
> > is only going to resolve from the local repo, not the reactor, right?
> wrong, I already:
> - explained it
> - updated maven-dependency-tree javadoc to keep track of explanations [1]
> - updated the reactor IT to prove that it runs as expected (ie not resolved
> before compile, but resolved after compile)
>
> Regards,
>
> Hervé
>
> [1]
> http://maven.apache.org/shared-archives/maven-dependency-tree-LATEST/apidocs/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.html
>
> >
> > William
> >
> > On Fri, Jun 20, 2014 at 4:58 AM, Daniel Kulp <dk...@apache.org> wrote:
> > > For Aries, I ended up doing:
> > >     @Component
> > >     private org.apache.maven.repository.RepositorySystem repository;
> > >
> > >     private File resolve(String artifactDescriptor) {
> > >
> > >         String[] s = artifactDescriptor.split(":");
> > >
> > >         String type = (s.length >= 4 ? s[3] : "jar");
> > >         Artifact artifact = repository.createArtifact(s[0], s[1], s[2],
> > >
> > > type);
> > >
> > >         ArtifactResolutionRequest request = new
> > >
> > > ArtifactResolutionRequest();
> > >
> > >         request.setArtifact(artifact);
> > >
> > >         request.setResolveRoot(true).setResolveTransitively(false);
> > >         request.setServers( session.getRequest().getServers() );
> > >         request.setMirrors( session.getRequest().getMirrors() );
> > >         request.setProxies( session.getRequest().getProxies() );
> > >         request.setLocalRepository(session.getLocalRepository());
> > >
> > >
> request.setRemoteRepositories(session.getRequest().getRemoteRepositories()
> > > );>
> > >         repository.resolve(request);
> > >         return artifact.getFile();
> > >
> > >     }
> > >
> > > If you set “setResolveTransitively(true)” then the
> > > ArtifactResolutionResponse would have all the deps available in it.
> > >
> > > That seems to work for both Maven 3.0 and 3.1/3.2.
> > >
> > > Dan
> > >
> > >
> > > Op Thu, 19 Jun 2014 00:01:52 +0200 schreef William Ferguson <
> > >
> > > william.ferguson@xandar.com.au>:
> > > > I asked on maven-users but didn't get any viable responses. So I'm
> > > > hoping
> > > > someone here can help.
> > > >
> > > > --------------------------
> > > > I have a Mojo that needs to work with Maven 3.0.* and 3.1+
> > > >
> > > > In the Mojo I have an Artifact and I need to resolve it's
> dependencies.
> > >
> > > How
> > >
> > > > can/should I do it?
> > > >
> > > > If I can resolve the Artifact to a MavenProject then I can use
> > > > DependencyGraphBuilder (from maven-dependency-tree) to construct a
> graph
> > >
> > > of
> > >
> > > > the deps. But I'm struggling to make the Artifact to MavenProject
> > > > conversion happen.
> > > >
> > > > I thought that If I could get a URL to the Artifact's POM file then I
> > >
> > > could
> > >
> > > > use DefaultMavenRuntime (maven-runtime) to resolve the URL into a
> > > > MavenProject. But
> > > >
> > > >   1. I can't work out how to get a URL to the artifact's POM file (it
> > > >   needs to handle both reactor artifacts and repo artifacts)
> > > >   2. Even with a URL to the POM file, MavenRuntime#getProject) is
> > > >   returning null.
> > > >
> > > > Can someone please point me in the right direction?
> > > > Am I even on the right path or is there a much more straight forward
> way
> > >
> > > of
> > >
> > > > getting the dependencies for the Artifact?
> > > > --------------------------
> > > >
> > > > William
> > >
> > > --
> > > Daniel Kulp
> > > dkulp@apache.org - http://dankulp.com/blog
> > > Talend Community Coder - http://coders.talend.com
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> > > For additional commands, e-mail: dev-help@maven.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>

Re: Resolving the dependencies for an Artifact

Posted by Hervé BOUTEMY <he...@free.fr>.
Le vendredi 20 juin 2014 08:36:46 William Ferguson a écrit :
> Hi Dan,
> 
> if the ArtifactResolutionResult contains the deps for the Artifact in the
> request then that's exactly what I want. However I can't see that it does.
> What am I missing?
> 
> NB the resolution also needs to be able to resolve Artifacts in the
> reactor. I'm pretty certain that
> 
> @Component
>     private org.apache.maven.repository.RepositorySystem repository;
> 
> is only going to resolve from the local repo, not the reactor, right?
wrong, I already:
- explained it
- updated maven-dependency-tree javadoc to keep track of explanations [1]
- updated the reactor IT to prove that it runs as expected (ie not resolved 
before compile, but resolved after compile)

Regards,

Hervé

[1] http://maven.apache.org/shared-archives/maven-dependency-tree-LATEST/apidocs/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.html

> 
> William
> 
> On Fri, Jun 20, 2014 at 4:58 AM, Daniel Kulp <dk...@apache.org> wrote:
> > For Aries, I ended up doing:
> >     @Component
> >     private org.apache.maven.repository.RepositorySystem repository;
> >     
> >     private File resolve(String artifactDescriptor) {
> >     
> >         String[] s = artifactDescriptor.split(":");
> >         
> >         String type = (s.length >= 4 ? s[3] : "jar");
> >         Artifact artifact = repository.createArtifact(s[0], s[1], s[2],
> > 
> > type);
> > 
> >         ArtifactResolutionRequest request = new
> > 
> > ArtifactResolutionRequest();
> > 
> >         request.setArtifact(artifact);
> >         
> >         request.setResolveRoot(true).setResolveTransitively(false);
> >         request.setServers( session.getRequest().getServers() );
> >         request.setMirrors( session.getRequest().getMirrors() );
> >         request.setProxies( session.getRequest().getProxies() );
> >         request.setLocalRepository(session.getLocalRepository());
> > 
> > request.setRemoteRepositories(session.getRequest().getRemoteRepositories()
> > );> 
> >         repository.resolve(request);
> >         return artifact.getFile();
> >     
> >     }
> > 
> > If you set “setResolveTransitively(true)” then the
> > ArtifactResolutionResponse would have all the deps available in it.
> > 
> > That seems to work for both Maven 3.0 and 3.1/3.2.
> > 
> > Dan
> > 
> > 
> > Op Thu, 19 Jun 2014 00:01:52 +0200 schreef William Ferguson <
> > 
> > william.ferguson@xandar.com.au>:
> > > I asked on maven-users but didn't get any viable responses. So I'm
> > > hoping
> > > someone here can help.
> > > 
> > > --------------------------
> > > I have a Mojo that needs to work with Maven 3.0.* and 3.1+
> > > 
> > > In the Mojo I have an Artifact and I need to resolve it's dependencies.
> > 
> > How
> > 
> > > can/should I do it?
> > > 
> > > If I can resolve the Artifact to a MavenProject then I can use
> > > DependencyGraphBuilder (from maven-dependency-tree) to construct a graph
> > 
> > of
> > 
> > > the deps. But I'm struggling to make the Artifact to MavenProject
> > > conversion happen.
> > > 
> > > I thought that If I could get a URL to the Artifact's POM file then I
> > 
> > could
> > 
> > > use DefaultMavenRuntime (maven-runtime) to resolve the URL into a
> > > MavenProject. But
> > > 
> > >   1. I can't work out how to get a URL to the artifact's POM file (it
> > >   needs to handle both reactor artifacts and repo artifacts)
> > >   2. Even with a URL to the POM file, MavenRuntime#getProject) is
> > >   returning null.
> > > 
> > > Can someone please point me in the right direction?
> > > Am I even on the right path or is there a much more straight forward way
> > 
> > of
> > 
> > > getting the dependencies for the Artifact?
> > > --------------------------
> > > 
> > > William
> > 
> > --
> > Daniel Kulp
> > dkulp@apache.org - http://dankulp.com/blog
> > Talend Community Coder - http://coders.talend.com
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> > For additional commands, e-mail: dev-help@maven.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: Resolving the dependencies for an Artifact

Posted by William Ferguson <wi...@xandar.com.au>.
>
>
> ArtifactResolutionResult.getArtifacts() is a list of all the artifacts
> that it resolved.
>


Yes, but aren't those the artifacts that matched the
ArtifactResolutionRequest?
They're not the dependencies of the target of an ArtifactResolutionRequest.

William



> > NB the resolution also needs to be able to resolve Artifacts in the
> > reactor. I'm pretty certain that
> >
> > @Component
> >    private org.apache.maven.repository.RepositorySystem repository;
> >
> > is only going to resolve from the local repo, not the reactor, right?
>
> This I don’t know.   I haven’t tried to have it resolve anything in the
> reactor.
>
> Dan
>
>
>
>
> > William
> >
> >
> > On Fri, Jun 20, 2014 at 4:58 AM, Daniel Kulp <dk...@apache.org> wrote:
> >
> >>
> >> For Aries, I ended up doing:
> >>
> >>
> >>    @Component
> >>    private org.apache.maven.repository.RepositorySystem repository;
> >>
> >>    private File resolve(String artifactDescriptor) {
> >>        String[] s = artifactDescriptor.split(":");
> >>
> >>        String type = (s.length >= 4 ? s[3] : "jar");
> >>        Artifact artifact = repository.createArtifact(s[0], s[1], s[2],
> >> type);
> >>
> >>        ArtifactResolutionRequest request = new
> >> ArtifactResolutionRequest();
> >>        request.setArtifact(artifact);
> >>
> >>        request.setResolveRoot(true).setResolveTransitively(false);
> >>        request.setServers( session.getRequest().getServers() );
> >>        request.setMirrors( session.getRequest().getMirrors() );
> >>        request.setProxies( session.getRequest().getProxies() );
> >>        request.setLocalRepository(session.getLocalRepository());
> >>
> >>
> request.setRemoteRepositories(session.getRequest().getRemoteRepositories());
> >>        repository.resolve(request);
> >>        return artifact.getFile();
> >>    }
> >>
> >> If you set “setResolveTransitively(true)” then the
> >> ArtifactResolutionResponse would have all the deps available in it.
> >>
> >> That seems to work for both Maven 3.0 and 3.1/3.2.
> >>
> >> Dan
> >>
> >>
> >> Op Thu, 19 Jun 2014 00:01:52 +0200 schreef William Ferguson <
> >> william.ferguson@xandar.com.au>:
> >>
> >>> I asked on maven-users but didn't get any viable responses. So I'm
> hoping
> >>> someone here can help.
> >>>
> >>> --------------------------
> >>> I have a Mojo that needs to work with Maven 3.0.* and 3.1+
> >>>
> >>> In the Mojo I have an Artifact and I need to resolve it's dependencies.
> >> How
> >>> can/should I do it?
> >>>
> >>> If I can resolve the Artifact to a MavenProject then I can use
> >>> DependencyGraphBuilder (from maven-dependency-tree) to construct a
> graph
> >> of
> >>> the deps. But I'm struggling to make the Artifact to MavenProject
> >>> conversion happen.
> >>>
> >>> I thought that If I could get a URL to the Artifact's POM file then I
> >> could
> >>> use DefaultMavenRuntime (maven-runtime) to resolve the URL into a
> >>> MavenProject. But
> >>>
> >>>  1. I can't work out how to get a URL to the artifact's POM file (it
> >>>  needs to handle both reactor artifacts and repo artifacts)
> >>>  2. Even with a URL to the POM file, MavenRuntime#getProject) is
> >>>  returning null.
> >>>
> >>> Can someone please point me in the right direction?
> >>> Am I even on the right path or is there a much more straight forward
> way
> >> of
> >>> getting the dependencies for the Artifact?
> >>> --------------------------
> >>>
> >>> William
> >>
> >>
> >> --
> >> Daniel Kulp
> >> dkulp@apache.org - http://dankulp.com/blog
> >> Talend Community Coder - http://coders.talend.com
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> >> For additional commands, e-mail: dev-help@maven.apache.org
> >>
> >>
>
> --
> Daniel Kulp
> dkulp@apache.org - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>

Re: Resolving the dependencies for an Artifact

Posted by William Ferguson <wi...@xandar.com.au>.
Thanks Dan.

I didn't appreciate at first the impact of setResolveTransitively(true).
NB I needed to change request.setResolveRoot(false) to exclude the provided
artifact.

William


On Fri, Jun 20, 2014 at 11:44 AM, Daniel Kulp <dk...@apache.org> wrote:

>
> On Jun 19, 2014, at 6:36 PM, William Ferguson <
> william.ferguson@xandar.com.au> wrote:
>
> > Hi Dan,
> >
> > if the ArtifactResolutionResult contains the deps for the Artifact in the
> > request then that's exactly what I want. However I can't see that it
> does.
> > What am I missing?
>
>
> ArtifactResolutionResult.getArtifacts() is a list of all the artifacts
> that it resolved.
>
> > NB the resolution also needs to be able to resolve Artifacts in the
> > reactor. I'm pretty certain that
> >
> > @Component
> >    private org.apache.maven.repository.RepositorySystem repository;
> >
> > is only going to resolve from the local repo, not the reactor, right?
>
> This I don’t know.   I haven’t tried to have it resolve anything in the
> reactor.
>
> Dan
>
>
>
>
> > William
> >
> >
> > On Fri, Jun 20, 2014 at 4:58 AM, Daniel Kulp <dk...@apache.org> wrote:
> >
> >>
> >> For Aries, I ended up doing:
> >>
> >>
> >>    @Component
> >>    private org.apache.maven.repository.RepositorySystem repository;
> >>
> >>    private File resolve(String artifactDescriptor) {
> >>        String[] s = artifactDescriptor.split(":");
> >>
> >>        String type = (s.length >= 4 ? s[3] : "jar");
> >>        Artifact artifact = repository.createArtifact(s[0], s[1], s[2],
> >> type);
> >>
> >>        ArtifactResolutionRequest request = new
> >> ArtifactResolutionRequest();
> >>        request.setArtifact(artifact);
> >>
> >>        request.setResolveRoot(true).setResolveTransitively(false);
> >>        request.setServers( session.getRequest().getServers() );
> >>        request.setMirrors( session.getRequest().getMirrors() );
> >>        request.setProxies( session.getRequest().getProxies() );
> >>        request.setLocalRepository(session.getLocalRepository());
> >>
> >>
> request.setRemoteRepositories(session.getRequest().getRemoteRepositories());
> >>        repository.resolve(request);
> >>        return artifact.getFile();
> >>    }
> >>
> >> If you set “setResolveTransitively(true)” then the
> >> ArtifactResolutionResponse would have all the deps available in it.
> >>
> >> That seems to work for both Maven 3.0 and 3.1/3.2.
> >>
> >> Dan
> >>
> >>
> >> Op Thu, 19 Jun 2014 00:01:52 +0200 schreef William Ferguson <
> >> william.ferguson@xandar.com.au>:
> >>
> >>> I asked on maven-users but didn't get any viable responses. So I'm
> hoping
> >>> someone here can help.
> >>>
> >>> --------------------------
> >>> I have a Mojo that needs to work with Maven 3.0.* and 3.1+
> >>>
> >>> In the Mojo I have an Artifact and I need to resolve it's dependencies.
> >> How
> >>> can/should I do it?
> >>>
> >>> If I can resolve the Artifact to a MavenProject then I can use
> >>> DependencyGraphBuilder (from maven-dependency-tree) to construct a
> graph
> >> of
> >>> the deps. But I'm struggling to make the Artifact to MavenProject
> >>> conversion happen.
> >>>
> >>> I thought that If I could get a URL to the Artifact's POM file then I
> >> could
> >>> use DefaultMavenRuntime (maven-runtime) to resolve the URL into a
> >>> MavenProject. But
> >>>
> >>>  1. I can't work out how to get a URL to the artifact's POM file (it
> >>>  needs to handle both reactor artifacts and repo artifacts)
> >>>  2. Even with a URL to the POM file, MavenRuntime#getProject) is
> >>>  returning null.
> >>>
> >>> Can someone please point me in the right direction?
> >>> Am I even on the right path or is there a much more straight forward
> way
> >> of
> >>> getting the dependencies for the Artifact?
> >>> --------------------------
> >>>
> >>> William
> >>
> >>
> >> --
> >> Daniel Kulp
> >> dkulp@apache.org - http://dankulp.com/blog
> >> Talend Community Coder - http://coders.talend.com
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> >> For additional commands, e-mail: dev-help@maven.apache.org
> >>
> >>
>
> --
> Daniel Kulp
> dkulp@apache.org - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>

Re: Resolving the dependencies for an Artifact

Posted by Daniel Kulp <dk...@apache.org>.
On Jun 19, 2014, at 6:36 PM, William Ferguson <wi...@xandar.com.au> wrote:

> Hi Dan,
> 
> if the ArtifactResolutionResult contains the deps for the Artifact in the
> request then that's exactly what I want. However I can't see that it does.
> What am I missing?


ArtifactResolutionResult.getArtifacts() is a list of all the artifacts that it resolved.

> NB the resolution also needs to be able to resolve Artifacts in the
> reactor. I'm pretty certain that
> 
> @Component
>    private org.apache.maven.repository.RepositorySystem repository;
> 
> is only going to resolve from the local repo, not the reactor, right?

This I don’t know.   I haven’t tried to have it resolve anything in the reactor.

Dan




> William
> 
> 
> On Fri, Jun 20, 2014 at 4:58 AM, Daniel Kulp <dk...@apache.org> wrote:
> 
>> 
>> For Aries, I ended up doing:
>> 
>> 
>>    @Component
>>    private org.apache.maven.repository.RepositorySystem repository;
>> 
>>    private File resolve(String artifactDescriptor) {
>>        String[] s = artifactDescriptor.split(":");
>> 
>>        String type = (s.length >= 4 ? s[3] : "jar");
>>        Artifact artifact = repository.createArtifact(s[0], s[1], s[2],
>> type);
>> 
>>        ArtifactResolutionRequest request = new
>> ArtifactResolutionRequest();
>>        request.setArtifact(artifact);
>> 
>>        request.setResolveRoot(true).setResolveTransitively(false);
>>        request.setServers( session.getRequest().getServers() );
>>        request.setMirrors( session.getRequest().getMirrors() );
>>        request.setProxies( session.getRequest().getProxies() );
>>        request.setLocalRepository(session.getLocalRepository());
>> 
>> request.setRemoteRepositories(session.getRequest().getRemoteRepositories());
>>        repository.resolve(request);
>>        return artifact.getFile();
>>    }
>> 
>> If you set “setResolveTransitively(true)” then the
>> ArtifactResolutionResponse would have all the deps available in it.
>> 
>> That seems to work for both Maven 3.0 and 3.1/3.2.
>> 
>> Dan
>> 
>> 
>> Op Thu, 19 Jun 2014 00:01:52 +0200 schreef William Ferguson <
>> william.ferguson@xandar.com.au>:
>> 
>>> I asked on maven-users but didn't get any viable responses. So I'm hoping
>>> someone here can help.
>>> 
>>> --------------------------
>>> I have a Mojo that needs to work with Maven 3.0.* and 3.1+
>>> 
>>> In the Mojo I have an Artifact and I need to resolve it's dependencies.
>> How
>>> can/should I do it?
>>> 
>>> If I can resolve the Artifact to a MavenProject then I can use
>>> DependencyGraphBuilder (from maven-dependency-tree) to construct a graph
>> of
>>> the deps. But I'm struggling to make the Artifact to MavenProject
>>> conversion happen.
>>> 
>>> I thought that If I could get a URL to the Artifact's POM file then I
>> could
>>> use DefaultMavenRuntime (maven-runtime) to resolve the URL into a
>>> MavenProject. But
>>> 
>>>  1. I can't work out how to get a URL to the artifact's POM file (it
>>>  needs to handle both reactor artifacts and repo artifacts)
>>>  2. Even with a URL to the POM file, MavenRuntime#getProject) is
>>>  returning null.
>>> 
>>> Can someone please point me in the right direction?
>>> Am I even on the right path or is there a much more straight forward way
>> of
>>> getting the dependencies for the Artifact?
>>> --------------------------
>>> 
>>> William
>> 
>> 
>> --
>> Daniel Kulp
>> dkulp@apache.org - http://dankulp.com/blog
>> Talend Community Coder - http://coders.talend.com
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
>> For additional commands, e-mail: dev-help@maven.apache.org
>> 
>> 

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: Resolving the dependencies for an Artifact

Posted by William Ferguson <wi...@xandar.com.au>.
Hi Dan,

if the ArtifactResolutionResult contains the deps for the Artifact in the
request then that's exactly what I want. However I can't see that it does.
What am I missing?

NB the resolution also needs to be able to resolve Artifacts in the
reactor. I'm pretty certain that

@Component
    private org.apache.maven.repository.RepositorySystem repository;

is only going to resolve from the local repo, not the reactor, right?

William


On Fri, Jun 20, 2014 at 4:58 AM, Daniel Kulp <dk...@apache.org> wrote:

>
> For Aries, I ended up doing:
>
>
>     @Component
>     private org.apache.maven.repository.RepositorySystem repository;
>
>     private File resolve(String artifactDescriptor) {
>         String[] s = artifactDescriptor.split(":");
>
>         String type = (s.length >= 4 ? s[3] : "jar");
>         Artifact artifact = repository.createArtifact(s[0], s[1], s[2],
> type);
>
>         ArtifactResolutionRequest request = new
> ArtifactResolutionRequest();
>         request.setArtifact(artifact);
>
>         request.setResolveRoot(true).setResolveTransitively(false);
>         request.setServers( session.getRequest().getServers() );
>         request.setMirrors( session.getRequest().getMirrors() );
>         request.setProxies( session.getRequest().getProxies() );
>         request.setLocalRepository(session.getLocalRepository());
>
> request.setRemoteRepositories(session.getRequest().getRemoteRepositories());
>         repository.resolve(request);
>         return artifact.getFile();
>     }
>
> If you set “setResolveTransitively(true)” then the
> ArtifactResolutionResponse would have all the deps available in it.
>
> That seems to work for both Maven 3.0 and 3.1/3.2.
>
> Dan
>
>
> Op Thu, 19 Jun 2014 00:01:52 +0200 schreef William Ferguson <
> william.ferguson@xandar.com.au>:
>
> > I asked on maven-users but didn't get any viable responses. So I'm hoping
> > someone here can help.
> >
> > --------------------------
> > I have a Mojo that needs to work with Maven 3.0.* and 3.1+
> >
> > In the Mojo I have an Artifact and I need to resolve it's dependencies.
> How
> > can/should I do it?
> >
> > If I can resolve the Artifact to a MavenProject then I can use
> > DependencyGraphBuilder (from maven-dependency-tree) to construct a graph
> of
> > the deps. But I'm struggling to make the Artifact to MavenProject
> > conversion happen.
> >
> > I thought that If I could get a URL to the Artifact's POM file then I
> could
> > use DefaultMavenRuntime (maven-runtime) to resolve the URL into a
> > MavenProject. But
> >
> >   1. I can't work out how to get a URL to the artifact's POM file (it
> >   needs to handle both reactor artifacts and repo artifacts)
> >   2. Even with a URL to the POM file, MavenRuntime#getProject) is
> >   returning null.
> >
> > Can someone please point me in the right direction?
> > Am I even on the right path or is there a much more straight forward way
> of
> > getting the dependencies for the Artifact?
> > --------------------------
> >
> > William
>
>
> --
> Daniel Kulp
> dkulp@apache.org - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>

Re: Resolving the dependencies for an Artifact

Posted by Daniel Kulp <dk...@apache.org>.
For Aries, I ended up doing:


    @Component
    private org.apache.maven.repository.RepositorySystem repository;

    private File resolve(String artifactDescriptor) {
        String[] s = artifactDescriptor.split(":");

        String type = (s.length >= 4 ? s[3] : "jar");
        Artifact artifact = repository.createArtifact(s[0], s[1], s[2], type);

        ArtifactResolutionRequest request = new ArtifactResolutionRequest();
        request.setArtifact(artifact);
        
        request.setResolveRoot(true).setResolveTransitively(false);
        request.setServers( session.getRequest().getServers() );
        request.setMirrors( session.getRequest().getMirrors() );
        request.setProxies( session.getRequest().getProxies() );
        request.setLocalRepository(session.getLocalRepository());
        request.setRemoteRepositories(session.getRequest().getRemoteRepositories());
        repository.resolve(request);
        return artifact.getFile();
    }

If you set “setResolveTransitively(true)” then the ArtifactResolutionResponse would have all the deps available in it.

That seems to work for both Maven 3.0 and 3.1/3.2.

Dan


Op Thu, 19 Jun 2014 00:01:52 +0200 schreef William Ferguson <wi...@xandar.com.au>:

> I asked on maven-users but didn't get any viable responses. So I'm hoping
> someone here can help.
> 
> --------------------------
> I have a Mojo that needs to work with Maven 3.0.* and 3.1+
> 
> In the Mojo I have an Artifact and I need to resolve it's dependencies. How
> can/should I do it?
> 
> If I can resolve the Artifact to a MavenProject then I can use
> DependencyGraphBuilder (from maven-dependency-tree) to construct a graph of
> the deps. But I'm struggling to make the Artifact to MavenProject
> conversion happen.
> 
> I thought that If I could get a URL to the Artifact's POM file then I could
> use DefaultMavenRuntime (maven-runtime) to resolve the URL into a
> MavenProject. But
> 
>   1. I can't work out how to get a URL to the artifact's POM file (it
>   needs to handle both reactor artifacts and repo artifacts)
>   2. Even with a URL to the POM file, MavenRuntime#getProject) is
>   returning null.
> 
> Can someone please point me in the right direction?
> Am I even on the right path or is there a much more straight forward way of
> getting the dependencies for the Artifact?
> --------------------------
> 
> William


-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: Resolving the dependencies for an Artifact

Posted by William Ferguson <wi...@xandar.com.au>.
>
> MG>If I understand a prioritised dependency shortcut of A->B then B->C
> (instead of A->C)?
> MG>put this on the Jason's wishlist for Maven 4.x!
> MG>does anyone know if Maven has ability to reorder the dependency graph?
>

I hadn't thought about that.
I could look into maven-dep-tree and see if I can determine what is doing
the optimisation (ie removing B->C) and provide another method that allows
the optimisation to be switched off.

But it's adding another method to the mdt DependencyResolver interface -
I've already added one in the last month :-). It's likely to be the only
consumer of the new method. And it feels a little clunky as I am still
resolving deps for A and then walking the graph until I find B to get B's
deps.

I would much rather just resolve deps for Artifact B.
But to do that I need to be able to convert Artifact B into MavenProject B.
Surely there has to be a way of doing that. Someone?

William


> >
> > William
> >
> >
> > On Fri, Jun 20, 2014 at 4:44 AM, Robert Scholte <rf...@apache.org>
> > wrote:
> >
> > > Hi William,
> > >
> > > most of the time it's not necessary to find a specific file like this,
> so
> > > I'm wondering what the usecase is.
> > >
> > > If you're hitting an issue, think of a plugin which might have the same
> > > issue and have a look at its code.
> > > In this case I'm thinking of the maven-dependency-plugin, especially
> the
> > > code for dependency:tree.
> > > Or use the org.apache.maven.project.ProjectBuilder
> > >
> > > thanks,
> > > Robert
> > >
> > > Op Thu, 19 Jun 2014 00:01:52 +0200 schreef William Ferguson <
> > > william.ferguson@xandar.com.au>:
> > >
> > >  I asked on maven-users but didn't get any viable responses. So I'm
> hoping
> > >> someone here can help.
> > >>
> > >> --------------------------
> > >> I have a Mojo that needs to work with Maven 3.0.* and 3.1+
> > >>
> > >> In the Mojo I have an Artifact and I need to resolve it's
> dependencies.
> > >> How
> > >> can/should I do it?
> > >>
> > >> If I can resolve the Artifact to a MavenProject then I can use
> > >> DependencyGraphBuilder (from maven-dependency-tree) to construct a
> graph
> > >> of
> > >> the deps. But I'm struggling to make the Artifact to MavenProject
> > >> conversion happen.
> > >>
> > >> I thought that If I could get a URL to the Artifact's POM file then I
> > >> could
> > >> use DefaultMavenRuntime (maven-runtime) to resolve the URL into a
> > >> MavenProject. But
> > >>
> > >>    1. I can't work out how to get a URL to the artifact's POM file (it
> > >>
> > >>    needs to handle both reactor artifacts and repo artifacts)
> > >>    2. Even with a URL to the POM file, MavenRuntime#getProject) is
> > >>
> > >>    returning null.
> > >>
> > >> Can someone please point me in the right direction?
> > >> Am I even on the right path or is there a much more straight forward
> way
> > >> of
> > >> getting the dependencies for the Artifact?
> > >> --------------------------
> > >>
> > >> William
> > >>
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> > > For additional commands, e-mail: dev-help@maven.apache.org
> > >
> > >
>
>

RE: Resolving the dependencies for an Artifact

Posted by Martin Gainty <mg...@hotmail.com>.

> Date: Fri, 20 Jun 2014 08:29:10 +1000
> Subject: Re: Resolving the dependencies for an Artifact
> From: william.ferguson@xandar.com.au
> To: dev@maven.apache.org
> 
> Hi Robert,
> 
> Use case is within the android-maven-plugin we need to generate artefacts
> for AAR (Android archive) dependencies when building a project.
> 
> When doing so we need to provide the dependencies of the AAR (not the
> project) into the generation tool. We can readily retrieve the deps for the
> AAR by looking through the dependency graph of the project until we find
> the AAR that then collect deps from there on.
> 
> This works fine for project (A) that has a dependency on B and C.
> But if A has dep on B & C and B also has a dep on C then it breaks because
> Maven's dependency resolution (for A, ie the project) will ignore the B->C
> dep because A->C is more direct. So when we look for the deps of B we never
> see C.
> 
> NB maven-dependency-plugin uses maven-dependency-tree for its resolution,
> which is where I've taken most of my lead so far.
> 
> It gets down to the context in which the resolution is being done. I need
> the context to be B instead of A and in order to do that I need to get the
> MavenProject for B. And this is where I am stuck.
MG>If I understand a prioritised dependency shortcut of A->B then B->C (instead of A->C)?
MG>put this on the Jason's wishlist for Maven 4.x!
MG>does anyone know if Maven has ability to reorder the dependency graph?
> 
> William
> 
> 
> On Fri, Jun 20, 2014 at 4:44 AM, Robert Scholte <rf...@apache.org>
> wrote:
> 
> > Hi William,
> >
> > most of the time it's not necessary to find a specific file like this, so
> > I'm wondering what the usecase is.
> >
> > If you're hitting an issue, think of a plugin which might have the same
> > issue and have a look at its code.
> > In this case I'm thinking of the maven-dependency-plugin, especially the
> > code for dependency:tree.
> > Or use the org.apache.maven.project.ProjectBuilder
> >
> > thanks,
> > Robert
> >
> > Op Thu, 19 Jun 2014 00:01:52 +0200 schreef William Ferguson <
> > william.ferguson@xandar.com.au>:
> >
> >  I asked on maven-users but didn't get any viable responses. So I'm hoping
> >> someone here can help.
> >>
> >> --------------------------
> >> I have a Mojo that needs to work with Maven 3.0.* and 3.1+
> >>
> >> In the Mojo I have an Artifact and I need to resolve it's dependencies.
> >> How
> >> can/should I do it?
> >>
> >> If I can resolve the Artifact to a MavenProject then I can use
> >> DependencyGraphBuilder (from maven-dependency-tree) to construct a graph
> >> of
> >> the deps. But I'm struggling to make the Artifact to MavenProject
> >> conversion happen.
> >>
> >> I thought that If I could get a URL to the Artifact's POM file then I
> >> could
> >> use DefaultMavenRuntime (maven-runtime) to resolve the URL into a
> >> MavenProject. But
> >>
> >>    1. I can't work out how to get a URL to the artifact's POM file (it
> >>
> >>    needs to handle both reactor artifacts and repo artifacts)
> >>    2. Even with a URL to the POM file, MavenRuntime#getProject) is
> >>
> >>    returning null.
> >>
> >> Can someone please point me in the right direction?
> >> Am I even on the right path or is there a much more straight forward way
> >> of
> >> getting the dependencies for the Artifact?
> >> --------------------------
> >>
> >> William
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> > For additional commands, e-mail: dev-help@maven.apache.org
> >
> >
 		 	   		  

Re: Resolving the dependencies for an Artifact

Posted by William Ferguson <wi...@xandar.com.au>.
Hi Robert,

Use case is within the android-maven-plugin we need to generate artefacts
for AAR (Android archive) dependencies when building a project.

When doing so we need to provide the dependencies of the AAR (not the
project) into the generation tool. We can readily retrieve the deps for the
AAR by looking through the dependency graph of the project until we find
the AAR that then collect deps from there on.

This works fine for project (A) that has a dependency on B and C.
But if A has dep on B & C and B also has a dep on C then it breaks because
Maven's dependency resolution (for A, ie the project) will ignore the B->C
dep because A->C is more direct. So when we look for the deps of B we never
see C.

NB maven-dependency-plugin uses maven-dependency-tree for its resolution,
which is where I've taken most of my lead so far.

It gets down to the context in which the resolution is being done. I need
the context to be B instead of A and in order to do that I need to get the
MavenProject for B. And this is where I am stuck.

William


On Fri, Jun 20, 2014 at 4:44 AM, Robert Scholte <rf...@apache.org>
wrote:

> Hi William,
>
> most of the time it's not necessary to find a specific file like this, so
> I'm wondering what the usecase is.
>
> If you're hitting an issue, think of a plugin which might have the same
> issue and have a look at its code.
> In this case I'm thinking of the maven-dependency-plugin, especially the
> code for dependency:tree.
> Or use the org.apache.maven.project.ProjectBuilder
>
> thanks,
> Robert
>
> Op Thu, 19 Jun 2014 00:01:52 +0200 schreef William Ferguson <
> william.ferguson@xandar.com.au>:
>
>  I asked on maven-users but didn't get any viable responses. So I'm hoping
>> someone here can help.
>>
>> --------------------------
>> I have a Mojo that needs to work with Maven 3.0.* and 3.1+
>>
>> In the Mojo I have an Artifact and I need to resolve it's dependencies.
>> How
>> can/should I do it?
>>
>> If I can resolve the Artifact to a MavenProject then I can use
>> DependencyGraphBuilder (from maven-dependency-tree) to construct a graph
>> of
>> the deps. But I'm struggling to make the Artifact to MavenProject
>> conversion happen.
>>
>> I thought that If I could get a URL to the Artifact's POM file then I
>> could
>> use DefaultMavenRuntime (maven-runtime) to resolve the URL into a
>> MavenProject. But
>>
>>    1. I can't work out how to get a URL to the artifact's POM file (it
>>
>>    needs to handle both reactor artifacts and repo artifacts)
>>    2. Even with a URL to the POM file, MavenRuntime#getProject) is
>>
>>    returning null.
>>
>> Can someone please point me in the right direction?
>> Am I even on the right path or is there a much more straight forward way
>> of
>> getting the dependencies for the Artifact?
>> --------------------------
>>
>> William
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>

Re: Resolving the dependencies for an Artifact

Posted by Robert Scholte <rf...@apache.org>.
Hi William,

most of the time it's not necessary to find a specific file like this, so  
I'm wondering what the usecase is.

If you're hitting an issue, think of a plugin which might have the same  
issue and have a look at its code.
In this case I'm thinking of the maven-dependency-plugin, especially the  
code for dependency:tree.
Or use the org.apache.maven.project.ProjectBuilder

thanks,
Robert

Op Thu, 19 Jun 2014 00:01:52 +0200 schreef William Ferguson  
<wi...@xandar.com.au>:

> I asked on maven-users but didn't get any viable responses. So I'm hoping
> someone here can help.
>
> --------------------------
> I have a Mojo that needs to work with Maven 3.0.* and 3.1+
>
> In the Mojo I have an Artifact and I need to resolve it's dependencies.  
> How
> can/should I do it?
>
> If I can resolve the Artifact to a MavenProject then I can use
> DependencyGraphBuilder (from maven-dependency-tree) to construct a graph  
> of
> the deps. But I'm struggling to make the Artifact to MavenProject
> conversion happen.
>
> I thought that If I could get a URL to the Artifact's POM file then I  
> could
> use DefaultMavenRuntime (maven-runtime) to resolve the URL into a
> MavenProject. But
>
>    1. I can't work out how to get a URL to the artifact's POM file (it
>    needs to handle both reactor artifacts and repo artifacts)
>    2. Even with a URL to the POM file, MavenRuntime#getProject) is
>    returning null.
>
> Can someone please point me in the right direction?
> Am I even on the right path or is there a much more straight forward way  
> of
> getting the dependencies for the Artifact?
> --------------------------
>
> William

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org