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 2024/03/15 07:43:02 UTC
(maven-assembly-plugin) branch master updated: [MASSEMBLY-1022] Unresolved artifacts should be not processed
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-assembly-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 74e858ad [MASSEMBLY-1022] Unresolved artifacts should be not processed
74e858ad is described below
commit 74e858ad40849cc3f8bef462e310336a8c6a0cd5
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Thu Mar 14 22:49:26 2024 +0100
[MASSEMBLY-1022] Unresolved artifacts should be not processed
---
src/it/projects/bugs/massembly-1022/pom.xml | 82 ++++++++++++++++++++++
.../bugs/massembly-1022/src/assembly/assembly.xml | 31 ++++++++
src/it/projects/bugs/massembly-1022/verify.groovy | 24 +++++++
.../artifact/DefaultDependencyResolver.java | 17 +++--
.../artifact/DefaultDependencyResolverTest.java | 13 ++--
5 files changed, 155 insertions(+), 12 deletions(-)
diff --git a/src/it/projects/bugs/massembly-1022/pom.xml b/src/it/projects/bugs/massembly-1022/pom.xml
new file mode 100644
index 00000000..abfa05e3
--- /dev/null
+++ b/src/it/projects/bugs/massembly-1022/pom.xml
@@ -0,0 +1,82 @@
+<!--
+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.plugin.assembly.test</groupId>
+ <artifactId>it-project-parent</artifactId>
+ <version>1</version>
+ </parent>
+
+ <groupId>test</groupId>
+ <artifactId>massembly-1022</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <description>
+ We have scope compile in assembly descriptor, so dependencies in runtime scope can be unresolved
+ </description>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.36</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.7.36</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <descriptors>
+ <descriptor>src/assembly/assembly.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/src/it/projects/bugs/massembly-1022/src/assembly/assembly.xml b/src/it/projects/bugs/massembly-1022/src/assembly/assembly.xml
new file mode 100644
index 00000000..e9fe4a92
--- /dev/null
+++ b/src/it/projects/bugs/massembly-1022/src/assembly/assembly.xml
@@ -0,0 +1,31 @@
+<!--
+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.
+-->
+<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
+
+ <id>assembly</id>
+ <includeBaseDirectory>false</includeBaseDirectory>
+
+ <dependencySets>
+ <dependencySet>
+ <scope>compile</scope>
+ </dependencySet>
+ </dependencySets>
+</assembly>
diff --git a/src/it/projects/bugs/massembly-1022/verify.groovy b/src/it/projects/bugs/massembly-1022/verify.groovy
new file mode 100644
index 00000000..50e5eaa7
--- /dev/null
+++ b/src/it/projects/bugs/massembly-1022/verify.groovy
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+import java.util.zip.ZipFile
+
+def zipFile = new ZipFile(new File(basedir, "target/massembly-1022-0.0.1-SNAPSHOT-assembly.zip"));
+assert zipFile.getEntry("slf4j-simple-1.7.36.jar") != null
+assert zipFile.entries().size() == 1
diff --git a/src/main/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolver.java b/src/main/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolver.java
index 6bbd7b00..e9eef03b 100644
--- a/src/main/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolver.java
+++ b/src/main/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolver.java
@@ -260,14 +260,19 @@ public class DefaultDependencyResolver implements DependencyResolver {
@Override
public boolean visitLeave(DependencyNode node) {
- if (node.getDependency() != null) {
+ Dependency dependency = node.getDependency();
+ if (dependency != null) {
Artifact artifact = aetherToMavenArtifacts.computeIfAbsent(
- node.getDependency().getArtifact(), RepositoryUtils::toArtifact);
- List<String> depTrail = new ArrayList<>();
- stack.descendingIterator().forEachRemaining(depTrail::add);
+ dependency.getArtifact(), RepositoryUtils::toArtifact);
+ if (artifact.isResolved() && artifact.getFile() != null) {
+ List<String> depTrail = new ArrayList<>();
+ stack.descendingIterator().forEachRemaining(depTrail::add);
+ artifact.setDependencyTrail(depTrail);
+ artifact.setOptional(dependency.isOptional());
+ artifact.setScope(dependency.getScope());
+ artifacts.add(artifact);
+ }
stack.pop();
- artifact.setDependencyTrail(depTrail);
- artifacts.add(artifact);
}
return true;
}
diff --git a/src/test/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolverTest.java b/src/test/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolverTest.java
index fb311754..362becf8 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolverTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolverTest.java
@@ -83,10 +83,10 @@ public class DefaultDependencyResolverTest {
artifacts.add(newArtifact("g.id", "a-id", "1"));
artifacts.add(newArtifact("g.id", "a-id-2", "2"));
- DefaultDependencyNode node1 = new DefaultDependencyNode(
- new Dependency(new org.eclipse.aether.artifact.DefaultArtifact("g.id:a-id:1"), "runtime"));
- DefaultDependencyNode node2 = new DefaultDependencyNode(
- new Dependency(new org.eclipse.aether.artifact.DefaultArtifact("g.id:a-id-2:2"), "runtime"));
+ DefaultDependencyNode node1 = new DefaultDependencyNode(new Dependency(
+ new org.eclipse.aether.artifact.DefaultArtifact("g.id:a-id:1").setFile(new File(".")), "runtime"));
+ DefaultDependencyNode node2 = new DefaultDependencyNode(new Dependency(
+ new org.eclipse.aether.artifact.DefaultArtifact("g.id:a-id-2:2").setFile(new File(".")), "runtime"));
DependencyResult dependencyResult = new DependencyResult(new DependencyRequest());
DefaultDependencyNode rootDependencyNode = new DefaultDependencyNode((Dependency) null);
@@ -177,8 +177,9 @@ public class DefaultDependencyResolverTest {
// FIXME - this is not checked - because ms.UseAllReactorProjects is false
ms.addInclude("*:module-1");
- DefaultDependencyNode node1 = new DefaultDependencyNode(
- new Dependency(new org.eclipse.aether.artifact.DefaultArtifact("group.id:module-1-dep:1"), "runtime"));
+ DefaultDependencyNode node1 = new DefaultDependencyNode(new Dependency(
+ new org.eclipse.aether.artifact.DefaultArtifact("group.id:module-1-dep:1").setFile(new File(".")),
+ "runtime"));
DependencyResult dependencyResult = new DependencyResult(new DependencyRequest());
DefaultDependencyNode rootDependencyNode = new DefaultDependencyNode((Dependency) null);