You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Laird Nelson <lj...@gmail.com> on 2017/03/17 23:01:21 UTC

Maven Resolver question regarding CollectRequest and mirrors

I'm proceeding further on my journey to do damage with the maven-resolver
series of projects (https://maven.apache.org/resolver/) in a way that looks
like Maven but doesn't use Maven itself (only these dependency resolution
components).

As I mentioned in some earlier posts to this list, I'm following the
general recipes laid out by the (now obsolete, but substantially OK) Aether
demos (
https://github.com/eclipse/aether-demo/tree/master/aether-demo-snippets/src/main/java/org/eclipse/aether/examples
).

In one of those examples, you put together a CollectRequest and ask a
RepositorySystem to resolve dependencies.  It goes something like this:

  final CollectRequest collectRequest = new CollectRequest();
  collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
  collectRequest.setRepositories(Collections.singletonList(mavenCentral));
// <-- I have questions here
  final DependencyRequest dependencyRequest = new
DependencyRequest(collectRequest, classpathFilter);
  final DependencyResult dependencyResult =
repositorySystem.resolveDependencies(repositorySystemSession,
dependencyRequest);

As part of setting this whole scaffolding up, I've found the global
settings file and the user settings file, and, using the maven-settings and
maven-settings-builder projects, figured out how to get a Settings object
in my hand in the same way that Maven "proper" does it.  From there, I can
get its mirrors, and so, it seems to me, I should be able to smash them
into my repositorySystemSession:

  final Collection<? extends Mirror> mirrors = settings.getMirrors();
  if (mirrors != null && !mirrors.isEmpty()) {
    final DefaultMirrorSelector mirrorSelector = new
DefaultMirrorSelector();
    for (final Mirror mirror : mirrors) {
      assert mirror != null;
      mirrorSelector.add(mirror.getId(), mirror.getUrl(),
mirror.getLayout(), false, mirror.getMirrorOf(),
mirror.getMirrorOfLayouts());
    }
    repositorySystemSession.setMirrorSelector(mirrorSelector); // <--
shouldn't this cause mirrors to be used transparently?
  }

My assumption would be that this MirrorSelector would be used transparently
somehow by the resolveDependencies() method, which, of course, has access
to the repositorySystemSession containing the MirrorSelector I built.

Nevertheless, I note that when I call
repositorySystem.resolveDependencies(repositorySystemSession,
dependencyRequest) (already excerpted above), the mirrors I've so
painstakingly installed into the session do not get used.

Am I doing something wrong?  How can I get my repository ecosystem I'm
building here to use mirrors?

Thanks,
Best,
Laird

Re: Maven Resolver question regarding CollectRequest and mirrors

Posted by Tamás Cservenák <ta...@cservenak.net>.
Howdy

Without deeply plunging in the problem, just figured you can look for code
examples here too

https://github.com/sonatype/sisu-maven-bridge/blob/master/bridge/src/main/java/org/sonatype/sisu/maven/bridge/support/settings/DefaultMavenSettings.java

As you may spot something your code missed.

HTH,
T

On Sat, Mar 18, 2017 at 12:08 AM Laird Nelson <lj...@gmail.com> wrote:

> On Fri, Mar 17, 2017 at 4:01 PM Laird Nelson <lj...@gmail.com> wrote:
>
> > Nevertheless, I note that when I call
> repositorySystem.resolveDependencies(repositorySystemSession,
> > dependencyRequest) (already excerpted above), the mirrors I've so
> > painstakingly installed into the session do not get used.
> >
>
> I wonder if that's what this method is for?  Hmm.
>
>
> https://maven.apache.org/resolver/apidocs/org/eclipse/aether/RepositorySystem.html#newResolutionRepositories(org.eclipse.aether.RepositorySystemSession,%20java.util.List)
>
> Best,
> Laird
>
-- 
Thanks,
~t~

Re: Maven Resolver question regarding CollectRequest and mirrors

Posted by Laird Nelson <lj...@gmail.com>.
On Fri, Mar 17, 2017 at 4:01 PM Laird Nelson <lj...@gmail.com> wrote:

> Nevertheless, I note that when I call repositorySystem.resolveDependencies(repositorySystemSession,
> dependencyRequest) (already excerpted above), the mirrors I've so
> painstakingly installed into the session do not get used.
>

I wonder if that's what this method is for?  Hmm.

https://maven.apache.org/resolver/apidocs/org/eclipse/aether/RepositorySystem.html#newResolutionRepositories(org.eclipse.aether.RepositorySystemSession,%20java.util.List)

Best,
Laird