You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2025/09/16 16:45:28 UTC
(maven-dependency-plugin) branch master updated: Use Resolver API in resolve-plugin
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new bc1893f4 Use Resolver API in resolve-plugin
bc1893f4 is described below
commit bc1893f40ddad014bc33d77621068dfd3b145455
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Mon Sep 15 23:57:23 2025 +0200
Use Resolver API in resolve-plugin
- change parent class to fewer details
- use parameter where is needed
- retrieve list of plugins from project reposting / build section
---
src/it/projects/resolve-plugins/pom.xml | 51 +++++
.../resolvers/PluginsIncludeExcludeFilter.java | 65 ++++++
.../resolvers/PluginsReactorExcludeFilter.java | 49 ++++
.../dependency/resolvers/ResolvePluginsMojo.java | 253 +++++++++++++--------
.../plugins/dependency/utils/ResolverUtil.java | 67 +++++-
5 files changed, 384 insertions(+), 101 deletions(-)
diff --git a/src/it/projects/resolve-plugins/pom.xml b/src/it/projects/resolve-plugins/pom.xml
index 5a20fa27..c0df8915 100644
--- a/src/it/projects/resolve-plugins/pom.xml
+++ b/src/it/projects/resolve-plugins/pom.xml
@@ -36,4 +36,55 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>3.7.1</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>3.5.4</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.18.0</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>3.5.4</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+
</project>
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/PluginsIncludeExcludeFilter.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/PluginsIncludeExcludeFilter.java
new file mode 100644
index 00000000..7de7a7f4
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/PluginsIncludeExcludeFilter.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.dependency.resolvers;
+
+import java.util.List;
+import java.util.function.Predicate;
+
+import org.apache.maven.model.Plugin;
+
+/**
+ * A filter to include or exclude plugins.
+ */
+class PluginsIncludeExcludeFilter implements Predicate<Plugin> {
+ private final List<String> includesGroupId;
+
+ private final List<String> excludesGroupId;
+
+ private final List<String> includesArtifactId;
+
+ private final List<String> excludesArtifactId;
+
+ PluginsIncludeExcludeFilter(
+ List<String> includeGroupIds,
+ List<String> excludeGroupIds,
+ List<String> includeArtifactIds,
+ List<String> excludeArtifactIds) {
+ this.includesGroupId = includeGroupIds;
+ this.excludesGroupId = excludeGroupIds;
+ this.includesArtifactId = includeArtifactIds;
+ this.excludesArtifactId = excludeArtifactIds;
+ }
+
+ @Override
+ public boolean test(Plugin plugin) {
+ if (!includesGroupId.isEmpty() && !includesGroupId.contains(plugin.getGroupId())) {
+ return false;
+ }
+
+ if (excludesGroupId.contains(plugin.getGroupId())) {
+ return false;
+ }
+
+ if (!includesArtifactId.isEmpty() && !includesArtifactId.contains(plugin.getArtifactId())) {
+ return false;
+ }
+
+ return !excludesArtifactId.contains(plugin.getArtifactId());
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/PluginsReactorExcludeFilter.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/PluginsReactorExcludeFilter.java
new file mode 100644
index 00000000..42c11c3a
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/PluginsReactorExcludeFilter.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.dependency.resolvers;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Predicate;
+
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * A filter to exclude plugins that are part of the current reactor build.
+ */
+class PluginsReactorExcludeFilter implements Predicate<Plugin> {
+
+ private final Set<String> reactorArtifactKeys;
+
+ PluginsReactorExcludeFilter(List<MavenProject> reactorProjects) {
+ this.reactorArtifactKeys = new LinkedHashSet<>(reactorProjects.size());
+ for (final MavenProject project : reactorProjects) {
+ this.reactorArtifactKeys.add(ArtifactUtils.key(project.getArtifact()));
+ }
+ }
+
+ @Override
+ public boolean test(Plugin plugin) {
+ String pluginKey = ArtifactUtils.key(plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion());
+ return !reactorArtifactKeys.contains(pluginKey);
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java
index d9f6a868..116fef91 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java
@@ -20,35 +20,34 @@ package org.apache.maven.plugins.dependency.resolvers;
import javax.inject.Inject;
+import java.io.File;
import java.io.IOException;
-import java.util.HashSet;
+import java.util.Collections;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
-import org.apache.maven.RepositoryUtils;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.ModelBase;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginContainer;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.Reporting;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.dependency.AbstractDependencyMojo;
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
import org.apache.maven.plugins.dependency.utils.ResolverUtil;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuilder;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
-import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
-import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
-import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
-import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult;
-import org.apache.maven.shared.transfer.dependencies.DefaultDependableCoordinate;
-import org.apache.maven.shared.transfer.dependencies.DependableCoordinate;
-import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;
-import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverException;
+import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.resolution.ArtifactResolutionException;
+import org.eclipse.aether.resolution.DependencyResolutionException;
import org.sonatype.plexus.build.incremental.BuildContext;
/**
@@ -58,8 +57,79 @@ import org.sonatype.plexus.build.incremental.BuildContext;
* @since 2.0
*/
@Mojo(name = "resolve-plugins", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
-public class ResolvePluginsMojo extends AbstractResolveMojo {
+public class ResolvePluginsMojo extends AbstractDependencyMojo {
+ /**
+ * If specified, this parameter causes the dependencies to be written to the path specified instead of
+ * the console.
+ *
+ * @since 2.0
+ */
+ @Parameter(property = "outputFile")
+ protected File outputFile;
+
+ /**
+ * If we should exclude transitive dependencies.
+ * This means only the plugin artifacts itself will be resolved not plugin dependencies.
+ *
+ * @since 2.0
+ */
+ @Parameter(property = "excludeTransitive", defaultValue = "false")
+ protected boolean excludeTransitive;
+
+ /**
+ * List of artifact IDs to exclude.
+ *
+ * @since 2.0
+ */
+ @Parameter(property = "excludeArtifactIds", defaultValue = "")
+ protected List<String> excludeArtifactIds;
+
+ /**
+ * List of artifact IDs to include. Empty list indicates include everything (default).
+ *
+ * @since 2.0
+ */
+ @Parameter(property = "includeArtifactIds", defaultValue = "")
+ protected List<String> includeArtifactIds;
+
+ /**
+ * List of group IDs to exclude.
+ *
+ * @since 2.0
+ */
+ @Parameter(property = "excludeGroupIds", defaultValue = "")
+ protected List<String> excludeGroupIds;
+
+ /**
+ * List of group IDs to include. Empty list indicates include everything (default).
+ *
+ * @since 2.0
+ */
+ @Parameter(property = "includeGroupIds", defaultValue = "")
+ protected List<String> includeGroupIds;
+
+ /**
+ * Whether to append outputs into the output file or overwrite it.
+ *
+ * @since 2.2
+ */
+ @Parameter(property = "appendOutput", defaultValue = "false")
+ protected boolean appendOutput;
+
+ /**
+ * Don't resolve plugins that are in the current reactor.
+ *
+ * @since 2.7
+ */
+ @Parameter(property = "excludeReactor", defaultValue = "true")
+ protected boolean excludeReactor;
+
+ /**
+ * The encoding of the output file.
+ *
+ * @since 3.2.0
+ */
@Parameter(property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}")
private String outputEncoding;
@@ -71,22 +141,14 @@ public class ResolvePluginsMojo extends AbstractResolveMojo {
@Parameter(property = "outputAbsoluteArtifactFilename", defaultValue = "false")
private boolean outputAbsoluteArtifactFilename;
- private final DependencyResolver dependencyResolver;
+ private final ResolverUtil resolverUtil;
@Inject
- // CHECKSTYLE_OFF: ParameterNumber
public ResolvePluginsMojo(
- MavenSession session,
- BuildContext buildContext,
- MavenProject project,
- ResolverUtil resolverUtil,
- DependencyResolver dependencyResolver,
- ProjectBuilder projectBuilder,
- ArtifactHandlerManager artifactHandlerManager) {
- super(session, buildContext, project, resolverUtil, projectBuilder, artifactHandlerManager);
- this.dependencyResolver = dependencyResolver;
+ MavenSession session, BuildContext buildContext, MavenProject project, ResolverUtil resolverUtil) {
+ super(session, buildContext, project);
+ this.resolverUtil = resolverUtil;
}
- // CHECKSTYLE_ON: ParameterNumber
/**
* Main entry into mojo. Gets the list of dependencies and iterates through displaying the resolved version.
@@ -97,7 +159,7 @@ public class ResolvePluginsMojo extends AbstractResolveMojo {
protected void doExecute() throws MojoExecutionException {
try {
// ideally this should either be DependencyCoordinates or DependencyNode
- final Set<Artifact> plugins = resolvePluginArtifacts();
+ final Set<Plugin> plugins = getProjectPlugins();
StringBuilder sb = new StringBuilder();
sb.append(System.lineSeparator());
@@ -107,42 +169,32 @@ public class ResolvePluginsMojo extends AbstractResolveMojo {
sb.append(" none");
sb.append(System.lineSeparator());
} else {
- for (Artifact plugin : plugins) {
+ for (Plugin plugin : plugins) {
+ Artifact pluginArtifact = resolverUtil.resolvePlugin(plugin);
String artifactFilename = null;
if (outputAbsoluteArtifactFilename) {
- try {
- // we want to print the absolute file name here
- artifactFilename =
- plugin.getFile().getAbsoluteFile().getPath();
- } catch (NullPointerException e) {
- // ignore the null pointer, we'll output a null string
- artifactFilename = null;
- }
+ // we want to print the absolute file name here
+ artifactFilename = Optional.ofNullable(pluginArtifact.getFile())
+ .map(File::getAbsoluteFile)
+ .map(File::getPath)
+ .orElse(null);
}
- String id = plugin.toString();
+ String id = pluginArtifact.toString();
sb.append(" ")
.append(id)
.append(outputAbsoluteArtifactFilename ? ":" + artifactFilename : "")
.append(System.lineSeparator());
if (!excludeTransitive) {
- DefaultDependableCoordinate pluginCoordinate = new DefaultDependableCoordinate();
- pluginCoordinate.setGroupId(plugin.getGroupId());
- pluginCoordinate.setArtifactId(plugin.getArtifactId());
- pluginCoordinate.setVersion(plugin.getVersion());
-
- for (final Artifact artifact : resolveArtifactDependencies(pluginCoordinate)) {
+ for (Artifact artifact : resolverUtil.resolveDependencies(plugin)) {
artifactFilename = null;
if (outputAbsoluteArtifactFilename) {
- try {
- // we want to print the absolute file name here
- artifactFilename =
- artifact.getFile().getAbsoluteFile().getPath();
- } catch (NullPointerException e) {
- // ignore the null pointer, we'll output a null string
- artifactFilename = null;
- }
+ // we want to print the absolute file name here
+ artifactFilename = Optional.ofNullable(artifact.getFile())
+ .map(File::getAbsoluteFile)
+ .map(File::getPath)
+ .orElse(null);
}
id = artifact.toString();
@@ -163,70 +215,71 @@ public class ResolvePluginsMojo extends AbstractResolveMojo {
DependencyUtil.write(output, outputFile, appendOutput, encoding);
}
}
- } catch (IOException
- | ArtifactFilterException
- | ArtifactResolverException
- | DependencyResolverException
- | ArtifactResolutionException e) {
+ } catch (IOException | ArtifactResolutionException | DependencyResolutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
/**
- * This method resolves all transitive dependencies of an artifact.
+ * This return plugin list of the project after applying the include/exclude filters.
*
- * @param artifact the artifact used to retrieve dependencies
- * @return resolved set of dependencies
- * @throws DependencyResolverException in case of error while resolving artifacts
+ * @return set of project plugin
*/
- private Set<Artifact> resolveArtifactDependencies(final DependableCoordinate artifact)
- throws DependencyResolverException {
- ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
-
- Iterable<ArtifactResult> artifactResults =
- dependencyResolver.resolveDependencies(buildingRequest, artifact, null);
+ private Set<Plugin> getProjectPlugins() {
- Set<Artifact> artifacts = new LinkedHashSet<>();
+ Predicate<Plugin> pluginsFilter = new PluginsIncludeExcludeFilter(
+ includeGroupIds, excludeGroupIds, includeArtifactIds, excludeArtifactIds);
- for (final ArtifactResult artifactResult : artifactResults) {
- artifacts.add(artifactResult.getArtifact());
+ Predicate<Plugin> reactorExclusionFilter = plugin -> true;
+ if (excludeReactor) {
+ reactorExclusionFilter = new PluginsReactorExcludeFilter(session.getProjects());
}
- return artifacts;
- }
+ List<Plugin> reportPlugins = Optional.ofNullable(getProject().getModel())
+ .map(ModelBase::getReporting)
+ .map(Reporting::getPlugins)
+ .orElse(Collections.emptyList())
+ .stream()
+ .map(this::toPlugin)
+ .collect(Collectors.toList());
- /**
- * This method resolves the plugin artifacts from the project.
- *
- * @return set of resolved plugin artifacts
- * @throws ArtifactFilterException in case of an error
- * @throws ArtifactResolverException in case of an error
- */
- private Set<Artifact> resolvePluginArtifacts()
- throws ArtifactFilterException, ArtifactResolverException, ArtifactResolutionException {
- final Set<Artifact> plugins = getProject().getPluginArtifacts();
- final Set<Artifact> reports = getProject().getReportArtifacts();
+ List<Plugin> projectPlugins = getProject().getBuild().getPlugins();
+
+ return new LinkedHashSet<Plugin>(reportPlugins.size() + projectPlugins.size()) {
+ {
+ addAll(reportPlugins);
+ addAll(projectPlugins);
+ }
+ }.stream().filter(reactorExclusionFilter).filter(pluginsFilter).collect(Collectors.toSet());
+ }
- Set<Artifact> artifacts = new HashSet<>();
- artifacts.addAll(reports);
- artifacts.addAll(plugins);
+ private Plugin toPlugin(ReportPlugin reportPlugin) {
+ // first look in the pluginManagement section
+ Plugin plugin = Optional.ofNullable(getProject().getBuild().getPluginManagement())
+ .map(PluginContainer::getPluginsAsMap)
+ .orElseGet(Collections::emptyMap)
+ .get(reportPlugin.getKey());
- final FilterArtifacts filter = getArtifactsFilter();
- artifacts = filter.filter(artifacts);
+ if (plugin == null) {
+ plugin = getProject().getBuild().getPluginsAsMap().get(reportPlugin.getKey());
+ }
- Set<Artifact> result = new HashSet<>();
- for (final Artifact artifact : new LinkedHashSet<>(artifacts)) {
+ if (plugin == null) {
+ plugin = new Plugin();
+ plugin.setGroupId(reportPlugin.getGroupId());
+ plugin.setArtifactId(reportPlugin.getArtifactId());
+ plugin.setVersion(reportPlugin.getVersion());
+ } else {
+ // override the version with the one from the report plugin if specified
+ if (reportPlugin.getVersion() != null) {
+ plugin.setVersion(reportPlugin.getVersion());
+ }
+ }
- org.eclipse.aether.artifact.Artifact resolveArtifact = getResolverUtil()
- .resolveArtifact(
- RepositoryUtils.toArtifact(artifact), getProject().getRemotePluginRepositories());
- result.add(RepositoryUtils.toArtifact(resolveArtifact));
+ if (plugin.getVersion() == null) {
+ plugin.setVersion("RELEASE");
}
- return result;
- }
- @Override
- protected ArtifactsFilter getMarkedArtifactFilter() {
- return null;
+ return plugin;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/utils/ResolverUtil.java b/src/main/java/org/apache/maven/plugins/dependency/utils/ResolverUtil.java
index 83e31dba..ad5b356d 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/utils/ResolverUtil.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/utils/ResolverUtil.java
@@ -29,7 +29,9 @@ import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
+import org.apache.maven.RepositoryUtils;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Plugin;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
@@ -102,6 +104,19 @@ public class ResolverUtil {
return result.getArtifact();
}
+ /**
+ * Resolve given plugin artifact.
+ *
+ * @param plugin a plugin to resolve
+ * @return resolved artifact
+ * @throws ArtifactResolutionException if the artifact could not be resolved
+ */
+ public Artifact resolvePlugin(Plugin plugin) throws ArtifactResolutionException {
+ MavenSession session = mavenSessionProvider.get();
+ Artifact artifact = toArtifact(plugin);
+ return resolveArtifact(artifact, session.getCurrentProject().getRemotePluginRepositories());
+ }
+
/**
* Resolve transitive dependencies for artifact.
*
@@ -113,16 +128,66 @@ public class ResolverUtil {
*/
public List<Artifact> resolveDependencies(Artifact artifact, List<RemoteRepository> repositories)
throws DependencyResolutionException {
+ return resolveDependencies(artifact, null, repositories);
+ }
+
+ /**
+ * Resolve transitive dependencies for artifact.
+ *
+ * @param artifact an artifact to resolve
+ * @param dependencies a list of additional dependencies for artifact
+ * @param repositories remote repositories list
+ * @return list of transitive dependencies for artifact
+ * @throws DependencyResolutionException if the dependency tree could not be built or any dependency artifact could
+ * not be resolved
+ */
+ public List<Artifact> resolveDependencies(
+ Artifact artifact, List<Dependency> dependencies, List<RemoteRepository> repositories)
+ throws DependencyResolutionException {
MavenSession session = mavenSessionProvider.get();
- CollectRequest collectRequest = new CollectRequest(new Dependency(artifact, null), repositories);
+ CollectRequest collectRequest = new CollectRequest(new Dependency(artifact, null), dependencies, repositories);
DependencyRequest request = new DependencyRequest(collectRequest, null);
+
DependencyResult result = repositorySystem.resolveDependencies(session.getRepositorySession(), request);
return result.getArtifactResults().stream()
.map(ArtifactResult::getArtifact)
.collect(Collectors.toList());
}
+ /**
+ * Resolve transitive dependencies for plugin.
+ *
+ * @param plugin aa plugin to resolve
+ * @return list of transitive dependencies for plugin
+ * @throws DependencyResolutionException if the dependency tree could not be built or any dependency artifact could
+ * not be resolved
+ */
+ public List<Artifact> resolveDependencies(final Plugin plugin) throws DependencyResolutionException {
+
+ MavenSession session = mavenSessionProvider.get();
+
+ org.eclipse.aether.artifact.Artifact artifact = toArtifact(plugin);
+ List<Dependency> pluginDependencies = plugin.getDependencies().stream()
+ .map(d -> RepositoryUtils.toDependency(
+ d, session.getRepositorySession().getArtifactTypeRegistry()))
+ .collect(Collectors.toList());
+
+ return resolveDependencies(
+ artifact, pluginDependencies, session.getCurrentProject().getRemoteProjectRepositories());
+ }
+
+ private Artifact toArtifact(Plugin plugin) {
+ MavenSession session = mavenSessionProvider.get();
+ return new DefaultArtifact(
+ plugin.getGroupId(),
+ plugin.getArtifactId(),
+ null,
+ "jar",
+ plugin.getVersion(),
+ session.getRepositorySession().getArtifactTypeRegistry().get("maven-plugin"));
+ }
+
/**
* Prepare a remote repositories list for given descriptions.
*