From 898cdf70f15247e18d43d00584a218a7e432e632 Mon Sep 17 00:00:00 2001 From: Fedor Dudinsky Date: Fri, 2 Oct 2026 15:14:04 +0200 Subject: [PATCH] Add an option for list to include/exclude module info Fixes https://github.com/apache/maven-dependency-plugin/issues/1715 --- .../list-no-modules/invoker.properties | 18 +++++++ src/it/projects/list-no-modules/pom.xml | 54 +++++++++++++++++++ .../projects/list-no-modules/test.properties | 20 +++++++ src/it/projects/list-no-modules/verify.groovy | 27 ++++++++++ .../resolvers/ResolveDependenciesMojo.java | 10 +++- 5 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 src/it/projects/list-no-modules/invoker.properties create mode 100644 src/it/projects/list-no-modules/pom.xml create mode 100644 src/it/projects/list-no-modules/test.properties create mode 100644 src/it/projects/list-no-modules/verify.groovy diff --git a/src/it/projects/list-no-modules/invoker.properties b/src/it/projects/list-no-modules/invoker.properties new file mode 100644 index 000000000..55afe77c1 --- /dev/null +++ b/src/it/projects/list-no-modules/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}:list diff --git a/src/it/projects/list-no-modules/pom.xml b/src/it/projects/list-no-modules/pom.xml new file mode 100644 index 000000000..264232ba3 --- /dev/null +++ b/src/it/projects/list-no-modules/pom.xml @@ -0,0 +1,54 @@ + + + + + 4.0.0 + + org.apache.maven.its.dependency + test + 1.0-SNAPSHOT + + Test + + Test dependency:list + + + + UTF-8 + + + + + fake-remote-repository + http://localhost:2345 + + + + + + org.apache.maven + maven-core + 3.9.9 + + + + \ No newline at end of file diff --git a/src/it/projects/list-no-modules/test.properties b/src/it/projects/list-no-modules/test.properties new file mode 100644 index 000000000..db661945f --- /dev/null +++ b/src/it/projects/list-no-modules/test.properties @@ -0,0 +1,20 @@ +# 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. + +outputFile = classpath.txt +includeModuleInfo = false + diff --git a/src/it/projects/list-no-modules/verify.groovy b/src/it/projects/list-no-modules/verify.groovy new file mode 100644 index 000000000..6b2d7947a --- /dev/null +++ b/src/it/projects/list-no-modules/verify.groovy @@ -0,0 +1,27 @@ +/* + * 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, "classpath.txt" ) +assert file.exists() : "output file $file does not exist" +String output = file.getText( "UTF-8" ) +assert output.startsWith( 'The following files have been resolved:') +// no escape codes +assert !output.contains( '\u001B' ) + +assert !output.contains( '-- module' ) : "Output should not contain module info" diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java index 9a59c73bc..7baf0c2d6 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java @@ -107,6 +107,14 @@ public class ResolveDependenciesMojo extends AbstractResolveMojo { @Parameter(property = "includeParents", defaultValue = "false") boolean includeParents; + /** + * Include module information + * + * @since 3.11 + */ + @Parameter(property = "includeModuleInfo", defaultValue = "true") + boolean includeModuleInfo; + @Inject // CHECKSTYLE_OFF: ParameterNumber public ResolveDependenciesMojo( @@ -232,7 +240,7 @@ private StringBuilder buildArtifactListOutput( } // dependencies:collect won't download jars - if (artifact.getFile() != null) { + if (includeModuleInfo && artifact.getFile() != null) { ModuleDescriptor moduleDescriptor = getModuleDescriptor(artifact.getFile()); if (moduleDescriptor != null) { messageBuilder.project(" -- module " + moduleDescriptor.name);