Skip to content

Commit 74e858a

Browse files
[MASSEMBLY-1022] Unresolved artifacts should be not processed
1 parent cb56382 commit 74e858a

File tree

5 files changed

+155
-12
lines changed

5 files changed

+155
-12
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<parent>
24+
<groupId>org.apache.maven.plugin.assembly.test</groupId>
25+
<artifactId>it-project-parent</artifactId>
26+
<version>1</version>
27+
</parent>
28+
29+
<groupId>test</groupId>
30+
<artifactId>massembly-1022</artifactId>
31+
<version>0.0.1-SNAPSHOT</version>
32+
<packaging>pom</packaging>
33+
34+
<description>
35+
We have scope compile in assembly descriptor, so dependencies in runtime scope can be unresolved
36+
</description>
37+
38+
<dependencyManagement>
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.slf4j</groupId>
42+
<artifactId>slf4j-api</artifactId>
43+
<version>1.7.36</version>
44+
<scope>runtime</scope>
45+
</dependency>
46+
</dependencies>
47+
</dependencyManagement>
48+
49+
<dependencies>
50+
<dependency>
51+
<groupId>org.slf4j</groupId>
52+
<artifactId>slf4j-simple</artifactId>
53+
<version>1.7.36</version>
54+
</dependency>
55+
</dependencies>
56+
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.apache.maven.plugins</groupId>
61+
<artifactId>maven-assembly-plugin</artifactId>
62+
<executions>
63+
<execution>
64+
<phase>package</phase>
65+
<goals>
66+
<goal>single</goal>
67+
</goals>
68+
</execution>
69+
</executions>
70+
<configuration>
71+
<formats>
72+
<format>zip</format>
73+
</formats>
74+
<descriptors>
75+
<descriptor>src/assembly/assembly.xml</descriptor>
76+
</descriptors>
77+
</configuration>
78+
</plugin>
79+
</plugins>
80+
</build>
81+
82+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
22+
23+
<id>assembly</id>
24+
<includeBaseDirectory>false</includeBaseDirectory>
25+
26+
<dependencySets>
27+
<dependencySet>
28+
<scope>compile</scope>
29+
</dependencySet>
30+
</dependencySets>
31+
</assembly>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import java.util.zip.ZipFile
21+
22+
def zipFile = new ZipFile(new File(basedir, "target/massembly-1022-0.0.1-SNAPSHOT-assembly.zip"));
23+
assert zipFile.getEntry("slf4j-simple-1.7.36.jar") != null
24+
assert zipFile.entries().size() == 1

src/main/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolver.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,19 @@ public boolean visitEnter(DependencyNode node) {
260260

261261
@Override
262262
public boolean visitLeave(DependencyNode node) {
263-
if (node.getDependency() != null) {
263+
Dependency dependency = node.getDependency();
264+
if (dependency != null) {
264265
Artifact artifact = aetherToMavenArtifacts.computeIfAbsent(
265-
node.getDependency().getArtifact(), RepositoryUtils::toArtifact);
266-
List<String> depTrail = new ArrayList<>();
267-
stack.descendingIterator().forEachRemaining(depTrail::add);
266+
dependency.getArtifact(), RepositoryUtils::toArtifact);
267+
if (artifact.isResolved() && artifact.getFile() != null) {
268+
List<String> depTrail = new ArrayList<>();
269+
stack.descendingIterator().forEachRemaining(depTrail::add);
270+
artifact.setDependencyTrail(depTrail);
271+
artifact.setOptional(dependency.isOptional());
272+
artifact.setScope(dependency.getScope());
273+
artifacts.add(artifact);
274+
}
268275
stack.pop();
269-
artifact.setDependencyTrail(depTrail);
270-
artifacts.add(artifact);
271276
}
272277
return true;
273278
}

src/test/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolverTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ public void test_getDependencySetResolutionRequirements_transitive() throws Exce
8383
artifacts.add(newArtifact("g.id", "a-id", "1"));
8484
artifacts.add(newArtifact("g.id", "a-id-2", "2"));
8585

86-
DefaultDependencyNode node1 = new DefaultDependencyNode(
87-
new Dependency(new org.eclipse.aether.artifact.DefaultArtifact("g.id:a-id:1"), "runtime"));
88-
DefaultDependencyNode node2 = new DefaultDependencyNode(
89-
new Dependency(new org.eclipse.aether.artifact.DefaultArtifact("g.id:a-id-2:2"), "runtime"));
86+
DefaultDependencyNode node1 = new DefaultDependencyNode(new Dependency(
87+
new org.eclipse.aether.artifact.DefaultArtifact("g.id:a-id:1").setFile(new File(".")), "runtime"));
88+
DefaultDependencyNode node2 = new DefaultDependencyNode(new Dependency(
89+
new org.eclipse.aether.artifact.DefaultArtifact("g.id:a-id-2:2").setFile(new File(".")), "runtime"));
9090

9191
DependencyResult dependencyResult = new DependencyResult(new DependencyRequest());
9292
DefaultDependencyNode rootDependencyNode = new DefaultDependencyNode((Dependency) null);
@@ -177,8 +177,9 @@ public void test_getModuleSetResolutionRequirements_includeDeps() throws Excepti
177177
// FIXME - this is not checked - because ms.UseAllReactorProjects is false
178178
ms.addInclude("*:module-1");
179179

180-
DefaultDependencyNode node1 = new DefaultDependencyNode(
181-
new Dependency(new org.eclipse.aether.artifact.DefaultArtifact("group.id:module-1-dep:1"), "runtime"));
180+
DefaultDependencyNode node1 = new DefaultDependencyNode(new Dependency(
181+
new org.eclipse.aether.artifact.DefaultArtifact("group.id:module-1-dep:1").setFile(new File(".")),
182+
"runtime"));
182183

183184
DependencyResult dependencyResult = new DependencyResult(new DependencyRequest());
184185
DefaultDependencyNode rootDependencyNode = new DefaultDependencyNode((Dependency) null);

0 commit comments

Comments
 (0)