diff --git a/src/main/java/org/simplify4u/plugins/ArtifactResolver.java b/src/main/java/org/simplify4u/plugins/ArtifactResolver.java index 26b2817f..8e351193 100644 --- a/src/main/java/org/simplify4u/plugins/ArtifactResolver.java +++ b/src/main/java/org/simplify4u/plugins/ArtifactResolver.java @@ -51,6 +51,8 @@ import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.collection.CollectRequest; import org.eclipse.aether.graph.Dependency; +import org.eclipse.aether.graph.DependencyNode; +import org.eclipse.aether.graph.DependencyVisitor; import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.repository.RepositoryPolicy; import org.eclipse.aether.resolution.ArtifactRequest; @@ -223,7 +225,7 @@ private List resolvePlugin(Plugin plugin, Configuration config) { if (config.verifyPluginDependencies) { // we need resolve all transitive dependencies - result = resolvePluginArtifactsTransitive(pArtifact, pluginDependencies, config.verifyPomFiles); + result = resolvePluginArtifactsTransitive(pArtifact, pluginDependencies, config.dependencyFilter, config.verifyPomFiles); } else { // only resolve plugin artifact List aeArtifacts = new ArrayList<>(); @@ -240,7 +242,7 @@ private List resolvePlugin(Plugin plugin, Configuration config) { private List resolvePluginArtifactsTransitive( org.eclipse.aether.artifact.Artifact artifact, - List dependencies, boolean verifyPomFiles) { + List dependencies, SkipFilter dependencyFilter, boolean verifyPomFiles) { CollectRequest collectRequest = new CollectRequest(new Dependency(artifact, "runtime"), remotePluginRepositories); @@ -252,12 +254,21 @@ private List resolvePluginArtifactsTransit .recover(DependencyResolutionException.class, DependencyResolutionException::getResult) .get(); - List result = new ArrayList<>( - dependencyResult.getArtifactResults().stream() - .map(aResult -> aResult.isResolved() ? - aResult.getArtifact() : - aResult.getRequest().getArtifact()) - .collect(Collectors.toList())); + List result = new ArrayList<>(); + dependencyResult.getRoot().accept(new DependencyVisitor() { + @Override + public boolean visitEnter(DependencyNode node) { + if (node.getArtifact() != null && !dependencyFilter.shouldSkipDependency(node.getDependency())) { + result.add(node.getArtifact()); + } + return true; + } + + @Override + public boolean visitLeave(DependencyNode node) { + return true; + } + }); if (verifyPomFiles) { resolvePoms(result, remotePluginRepositories); diff --git a/src/main/java/org/simplify4u/plugins/skipfilters/SkipFilter.java b/src/main/java/org/simplify4u/plugins/skipfilters/SkipFilter.java index d4b1b022..a2605572 100644 --- a/src/main/java/org/simplify4u/plugins/skipfilters/SkipFilter.java +++ b/src/main/java/org/simplify4u/plugins/skipfilters/SkipFilter.java @@ -16,6 +16,7 @@ package org.simplify4u.plugins.skipfilters; +import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; @@ -53,4 +54,12 @@ default boolean shouldSkipDependency(Dependency dependency, ArtifactHandlerManag artifactHandlerManager.getArtifactHandler(dependency.getType())); return shouldSkipArtifact(artifact); } + + default boolean shouldSkipDependency(org.eclipse.aether.graph.Dependency dependency) { + + Artifact artifact = RepositoryUtils.toArtifact(dependency.getArtifact()); + artifact.setScope(dependency.getScope()); + artifact.setOptional(dependency.getOptional()); + return shouldSkipArtifact(artifact); + } }