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

Reply via email to