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 ba3c570e Apply excludeReactor to plugin dependencies in go-offline and
resolve-plugins
ba3c570e is described below
commit ba3c570e3de0b113a07acce0be7e50686fc48c84
Author: Slawomir Jaranowski <[email protected]>
AuthorDate: Tue Jan 27 22:09:18 2026 +0100
Apply excludeReactor to plugin dependencies in go-offline and
resolve-plugins
fix #1543
---
.../go-offline-ractor-exclude/invoker.properties | 18 ++++++
.../go-offline-ractor-exclude/module1/pom.xml | 53 ++++++++++++++++++
.../go-offline-ractor-exclude/module2/pom.xml | 65 ++++++++++++++++++++++
.../go-offline-ractor-exclude/plugin/pom.xml | 33 +++++++++++
src/it/projects/go-offline-ractor-exclude/pom.xml | 45 +++++++++++++++
.../go-offline-ractor-exclude/verify.groovy | 39 +++++++++++++
.../plugins/dependency/AbstractDependencyMojo.java | 8 ---
.../dependency/resolvers/GoOfflineMojo.java | 16 ++++--
.../dependency/resolvers/ResolvePluginsMojo.java | 11 +++-
.../plugins/dependency/utils/ResolverUtil.java | 9 ++-
10 files changed, 281 insertions(+), 16 deletions(-)
diff --git a/src/it/projects/go-offline-ractor-exclude/invoker.properties
b/src/it/projects/go-offline-ractor-exclude/invoker.properties
new file mode 100644
index 00000000..e5961219
--- /dev/null
+++ b/src/it/projects/go-offline-ractor-exclude/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals =
${project.groupId}:${project.artifactId}:${project.version}:go-offline
diff --git a/src/it/projects/go-offline-ractor-exclude/module1/pom.xml
b/src/it/projects/go-offline-ractor-exclude/module1/pom.xml
new file mode 100644
index 00000000..b293fe8d
--- /dev/null
+++ b/src/it/projects/go-offline-ractor-exclude/module1/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>module1</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.9.11</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>3.5.0</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
diff --git a/src/it/projects/go-offline-ractor-exclude/module2/pom.xml
b/src/it/projects/go-offline-ractor-exclude/module2/pom.xml
new file mode 100644
index 00000000..4600add8
--- /dev/null
+++ b/src/it/projects/go-offline-ractor-exclude/module2/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>module2</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>module1</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.5.0</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>module1</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
diff --git a/src/it/projects/go-offline-ractor-exclude/plugin/pom.xml
b/src/it/projects/go-offline-ractor-exclude/plugin/pom.xml
new file mode 100644
index 00000000..abe9cb86
--- /dev/null
+++ b/src/it/projects/go-offline-ractor-exclude/plugin/pom.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>plugin</artifactId>
+</project>
diff --git a/src/it/projects/go-offline-ractor-exclude/pom.xml
b/src/it/projects/go-offline-ractor-exclude/pom.xml
new file mode 100644
index 00000000..245f9c0c
--- /dev/null
+++ b/src/it/projects/go-offline-ractor-exclude/pom.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <name>Test</name>
+ <description>
+ Test dependency:go-offline with reactor exclude
+ </description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <modules>
+ <module>module1</module>
+ <module>module2</module>
+ <module>plugin</module>
+ </modules>
+</project>
diff --git a/src/it/projects/go-offline-ractor-exclude/verify.groovy
b/src/it/projects/go-offline-ractor-exclude/verify.groovy
new file mode 100644
index 00000000..b159c567
--- /dev/null
+++ b/src/it/projects/go-offline-ractor-exclude/verify.groovy
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+File file = new File(basedir, 'build.log')
+assert file.exists()
+
+String buildLog = file.getText("UTF-8")
+
+assert buildLog.contains('[INFO] Resolved plugin:
maven-clean-plugin-3.5.0.jar')
+assert buildLog.contains('[INFO] Resolved plugin dependency:')
+assert buildLog.contains('[INFO] maven-clean-plugin-3.5.0.jar')
+assert buildLog.contains('[INFO] plexus-utils-4.0.2.jar')
+
+assert buildLog.contains('[INFO] Resolved plugin: maven-jar-plugin-3.5.0.jar')
+
+assert buildLog.contains('[INFO] Resolved dependency: maven-core-3.9.11.jar')
+assert buildLog.contains('[INFO] Resolved dependency: maven-model-3.9.11.jar')
+assert buildLog.contains('[INFO] Resolved dependency:
maven-settings-3.9.11.jar')
+
+assert buildLog.contains('[DEBUG] Skipped artifact
org.apache.maven.its.dependency:module1:1.0-SNAPSHOT because it is present in
the reactor')
+assert buildLog.contains('[DEBUG] Skipped dependency
org.apache.maven.its.dependency:module1:1.0-SNAPSHOT because it is present in
the reactor')
+
+
diff --git
a/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
b/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
index 47296eb7..933804b4 100644
---
a/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
+++
b/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
@@ -18,8 +18,6 @@
*/
package org.apache.maven.plugins.dependency;
-import java.util.List;
-
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -35,12 +33,6 @@ import org.sonatype.plexus.build.incremental.BuildContext;
*/
public abstract class AbstractDependencyMojo extends AbstractMojo {
- /**
- * Contains the full list of projects in the reactor.
- */
- @Parameter(defaultValue = "${reactorProjects}", readonly = true)
- protected List<MavenProject> reactorProjects;
-
/**
* The Maven session.
*/
diff --git
a/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
b/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
index e86d0f83..110b294a 100644
---
a/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
+++
b/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
@@ -81,7 +81,6 @@ public class GoOfflineMojo extends
AbstractDependencyFilterMojo {
protected boolean excludeReactor;
@Inject
- // CHECKSTYLE_OFF: ParameterNumber
public GoOfflineMojo(
MavenSession session,
BuildContext buildContext,
@@ -91,7 +90,6 @@ public class GoOfflineMojo extends
AbstractDependencyFilterMojo {
ArtifactHandlerManager artifactHandlerManager) {
super(session, buildContext, project, resolverUtil, projectBuilder,
artifactHandlerManager);
}
- // CHECKSTYLE_ON: ParameterNumber
/**
* Main entry into mojo. Gets the list of dependencies, resolves all that
are not in the Reactor, and iterates
@@ -114,7 +112,7 @@ public class GoOfflineMojo extends
AbstractDependencyFilterMojo {
if (!excludeTransitive) {
logMessage("Resolved plugin dependency:");
List<org.eclipse.aether.artifact.Artifact> artifacts =
- getResolverUtil().resolveDependencies(plugin);
+ getResolverUtil().resolveDependencies(plugin,
getDependencyFilter());
for (org.eclipse.aether.artifact.Artifact a : artifacts) {
logMessage(
" " +
DependencyUtil.getFormattedFileName(RepositoryUtils.toArtifact(a), false));
@@ -134,6 +132,14 @@ public class GoOfflineMojo extends
AbstractDependencyFilterMojo {
}
}
+ private Predicate<Dependency> getDependencyFilter() {
+ if (excludeReactor) {
+ return new
ExcludeReactorProjectsDependencyFilter(session.getProjects());
+ } else {
+ return __ -> true;
+ }
+ }
+
private void logMessage(String message) {
if (isSilent()) {
getLog().debug(message);
@@ -157,7 +163,7 @@ public class GoOfflineMojo extends
AbstractDependencyFilterMojo {
Predicate<Dependency> excludeReactorProjectsDependencyFilter = d ->
true;
if (this.excludeReactor) {
- excludeReactorProjectsDependencyFilter = new
ExcludeReactorProjectsDependencyFilter(this.reactorProjects);
+ excludeReactorProjectsDependencyFilter = new
ExcludeReactorProjectsDependencyFilter(session.getProjects());
}
ArtifactTypeRegistry artifactTypeRegistry =
@@ -265,7 +271,7 @@ public class GoOfflineMojo extends
AbstractDependencyFilterMojo {
final FilterArtifacts filter = new FilterArtifacts();
if (excludeReactor) {
- filter.addFilter(new
ExcludeReactorProjectsArtifactFilter(reactorProjects, getLog()));
+ filter.addFilter(new
ExcludeReactorProjectsArtifactFilter(session.getProjects(), getLog()));
}
filter.addFilter(new ScopeFilter(
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 2840ae61..1503bc0f 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
@@ -30,6 +30,7 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -181,7 +182,7 @@ public class ResolvePluginsMojo extends
AbstractDependencyMojo {
.append(System.lineSeparator());
if (!excludeTransitive) {
- for (Artifact artifact :
resolverUtil.resolveDependencies(plugin)) {
+ for (Artifact artifact :
resolverUtil.resolveDependencies(plugin, getDependencyFilter())) {
artifactFilename = null;
if (outputAbsoluteArtifactFilename) {
// we want to print the absolute file name here
@@ -214,6 +215,14 @@ public class ResolvePluginsMojo extends
AbstractDependencyMojo {
}
}
+ private Predicate<Dependency> getDependencyFilter() {
+ if (excludeReactor) {
+ return new
ExcludeReactorProjectsDependencyFilter(session.getProjects());
+ } else {
+ return __ -> true;
+ }
+ }
+
/**
* This return plugin list of the project after applying the
include/exclude filters.
*
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 3976abaa..27e56e91 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
@@ -30,6 +30,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
+import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.apache.maven.RepositoryUtils;
@@ -195,17 +196,21 @@ public class ResolverUtil {
/**
* Resolve transitive dependencies for plugin.
*
- * @param plugin aa plugin to resolve
+ * @param plugin a plugin to resolve
+ * @param dependencyFilter a filter to apply to plugin dependencies
* @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 {
+ public List<Artifact> resolveDependencies(
+ final Plugin plugin, Predicate<org.apache.maven.model.Dependency>
dependencyFilter)
+ throws DependencyResolutionException {
MavenSession session = mavenSessionProvider.get();
org.eclipse.aether.artifact.Artifact artifact = toArtifact(plugin);
List<Dependency> pluginDependencies = plugin.getDependencies().stream()
+ .filter(dependencyFilter)
.map(d -> RepositoryUtils.toDependency(
d,
session.getRepositorySession().getArtifactTypeRegistry()))
.collect(Collectors.toList());