You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2023/11/15 12:37:24 UTC

(maven-assembly-plugin) branch massembly-1008 created (now 23442c0e)

This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a change to branch massembly-1008
in repository https://gitbox.apache.org/repos/asf/maven-assembly-plugin.git


      at 23442c0e [MASSEMBLY-1008] Wrong use of dependency scopes

This branch includes the following new commits:

     new 23442c0e [MASSEMBLY-1008] Wrong use of dependency scopes

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven-assembly-plugin) 01/01: [MASSEMBLY-1008] Wrong use of dependency scopes

Posted by cs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch massembly-1008
in repository https://gitbox.apache.org/repos/asf/maven-assembly-plugin.git

commit 23442c0ea1046c565e4b3f130ba3073bdf1d2bb8
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Wed Nov 15 13:28:53 2023 +0100

    [MASSEMBLY-1008] Wrong use of dependency scopes
    
    This IT demonstrates how assembly plugin (among others)
    does wrongly, the code probably originates from Maven2
    times.
    
    What happens:
    * "single" mojo resolves test project dependencies
    * then it reads assembly descriptor
    * then uses project dependencies to deliver descriptor contents
    
    But, here is a problem that IT demonstrates: the delivered list
    of files are NOT runtime scoped, they are "test scope filtered
    for runtime leaves" which is not the same thing. By the way,
    dependency plugin demonstrates same behaviour, wrongly assumes
    that "test" graph is larger "runtime" tree, but that is not true
    nor was never true since Maven3 (resolver), it was true ONLY in
    Maven2 times.
---
 pom.xml                                            | 13 +----
 .../dependency-sets/massembly-1008/pom.xml         | 68 ++++++++++++++++++++++
 .../massembly-1008/src/main/assembly/bin.xml       | 33 +++++++++++
 .../dependency-sets/massembly-1008/verify.groovy   | 48 +++++++++++++++
 .../archive/task/AddDependencySetsTaskTest.java    | 10 ++--
 5 files changed, 157 insertions(+), 15 deletions(-)

diff --git a/pom.xml b/pom.xml
index f757c4b3..6e262de7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,7 +44,7 @@ under the License.
   </contributors>
 
   <prerequisites>
-    <maven>${mavenVersion}</maven>
+    <maven>3.2.5</maven>
   </prerequisites>
 
   <scm>
@@ -71,8 +71,8 @@ under the License.
   <properties>
     <javaVersion>8</javaVersion>
     <mdoVersion>2.2.0</mdoVersion>
-    <mavenVersion>3.2.5</mavenVersion>
-    <slf4jVersion>1.7.5</slf4jVersion>
+    <mavenVersion>3.9.5</mavenVersion>
+    <slf4jVersion>1.7.36</slf4jVersion>
     <mavenFilteringVersion>3.3.1</mavenFilteringVersion>
     <mavenArchiverVersion>3.6.0</mavenArchiverVersion>
 
@@ -105,13 +105,6 @@ under the License.
       <version>${mavenVersion}</version>
       <scope>provided</scope>
     </dependency>
-    <dependency>
-      <groupId>org.eclipse.aether</groupId>
-      <artifactId>aether-api</artifactId>
-      <!-- the same version as in Maven 3.2.5 -->
-      <version>1.0.0.v20140518</version>
-      <scope>provided</scope>
-    </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
diff --git a/src/it/projects/dependency-sets/massembly-1008/pom.xml b/src/it/projects/dependency-sets/massembly-1008/pom.xml
new file mode 100644
index 00000000..f4911046
--- /dev/null
+++ b/src/it/projects/dependency-sets/massembly-1008/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0"?>
+<!--
+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-1008</artifactId>
+    <version>1</version>
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>com.google.inject</groupId>
+            <artifactId>guice</artifactId>
+            <version>6.0.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>31.0.1-jre</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>assembly</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                        <configuration>
+                            <descriptors>
+                                <descriptor>src/main/assembly/bin.xml</descriptor>
+                            </descriptors>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/src/it/projects/dependency-sets/massembly-1008/src/main/assembly/bin.xml b/src/it/projects/dependency-sets/massembly-1008/src/main/assembly/bin.xml
new file mode 100644
index 00000000..acd9c04c
--- /dev/null
+++ b/src/it/projects/dependency-sets/massembly-1008/src/main/assembly/bin.xml
@@ -0,0 +1,33 @@
+<!--
+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>
+  <id>bin</id>
+  <formats>
+    <format>dir</format>
+  </formats>
+  <includeBaseDirectory>false</includeBaseDirectory>
+  <dependencySets>
+    <dependencySet>
+      <unpack>false</unpack>
+      <scope>runtime</scope>
+      <outputDirectory></outputDirectory>
+      <useProjectArtifact>false</useProjectArtifact>
+    </dependencySet>
+  </dependencySets>
+</assembly>
\ No newline at end of file
diff --git a/src/it/projects/dependency-sets/massembly-1008/verify.groovy b/src/it/projects/dependency-sets/massembly-1008/verify.groovy
new file mode 100644
index 00000000..55d7b281
--- /dev/null
+++ b/src/it/projects/dependency-sets/massembly-1008/verify.groovy
@@ -0,0 +1,48 @@
+/*
+ * 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.io.*;
+
+def expectedFilenames = [
+        "aopalliance-1.0.jar",
+        "checker-qual-3.12.0.jar",
+        "error_prone_annotations-2.7.1.jar",
+        "failureaccess-1.0.1.jar",
+        "guava-31.0.1-jre.jar",
+        "guice-6.0.0.jar",
+        "j2objc-annotations-1.3.jar",
+        "jakarta.inject-api-2.0.1.jar",
+        "javax.inject-1.jar",
+        "jsr305-3.0.2.jar",
+        "listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar"
+]
+
+File assemblyBasedir = new File( basedir, "target/massembly-1008-1-bin/" )
+
+assert assemblyBasedir.listFiles().length == expectedFilenames.size()
+
+for ( fileName in expectedFilenames )
+{
+  File file = new File( assemblyBasedir, fileName )
+  assert file.isFile() // exists and is file
+}
+
+// defined set vs listed set: same cardinality and all present: OK
+
+return true
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java
index 8908ea61..d7aabe7d 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java
@@ -37,6 +37,7 @@ import org.apache.maven.plugins.assembly.archive.DefaultAssemblyArchiverTest;
 import org.apache.maven.plugins.assembly.format.AssemblyFormattingException;
 import org.apache.maven.plugins.assembly.model.DependencySet;
 import org.apache.maven.plugins.assembly.model.UnpackOptions;
+import org.apache.maven.project.DefaultProjectBuildingRequest;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuilder;
 import org.apache.maven.project.ProjectBuildingException;
@@ -123,7 +124,7 @@ public class AddDependencySetsTaskTest {
                 .thenReturn(pbr);
 
         final MavenSession session = mock(MavenSession.class);
-        when(session.getProjectBuildingRequest()).thenReturn(mock(ProjectBuildingRequest.class));
+        when(session.getProjectBuildingRequest()).thenReturn(new DefaultProjectBuildingRequest());
         when(session.getExecutionProperties()).thenReturn(new Properties());
 
         final AssemblerConfigurationSource configSource = mock(AssemblerConfigurationSource.class);
@@ -210,7 +211,7 @@ public class AddDependencySetsTaskTest {
                 .thenThrow(pbe);
 
         final MavenSession session = mock(MavenSession.class);
-        when(session.getProjectBuildingRequest()).thenReturn(mock(ProjectBuildingRequest.class));
+        when(session.getProjectBuildingRequest()).thenReturn(new DefaultProjectBuildingRequest());
         when(session.getExecutionProperties()).thenReturn(new Properties());
 
         final AssemblerConfigurationSource configSource = mock(AssemblerConfigurationSource.class);
@@ -268,7 +269,7 @@ public class AddDependencySetsTaskTest {
         ds.setFileMode(Integer.toString(10, 8));
 
         final MavenSession session = mock(MavenSession.class);
-        when(session.getProjectBuildingRequest()).thenReturn(mock(ProjectBuildingRequest.class));
+        when(session.getProjectBuildingRequest()).thenReturn(new DefaultProjectBuildingRequest());
         when(session.getExecutionProperties()).thenReturn(new Properties());
 
         final AssemblerConfigurationSource configSource = mock(AssemblerConfigurationSource.class);
@@ -441,7 +442,6 @@ public class AddDependencySetsTaskTest {
         final MavenProject project = new MavenProject(new Model());
         project.setGroupId("GROUPID");
 
-        ProjectBuildingRequest pbReq = mock(ProjectBuildingRequest.class);
         ProjectBuildingResult pbRes = mock(ProjectBuildingResult.class);
         when(pbRes.getProject()).thenReturn(project);
 
@@ -453,7 +453,7 @@ public class AddDependencySetsTaskTest {
                 new AddDependencySetsTask(Collections.singletonList(dependencySet), artifacts, project, projectBuilder);
 
         final MavenSession session = mock(MavenSession.class);
-        when(session.getProjectBuildingRequest()).thenReturn(pbReq);
+        when(session.getProjectBuildingRequest()).thenReturn(new DefaultProjectBuildingRequest());
 
         final AssemblerConfigurationSource configSource = mock(AssemblerConfigurationSource.class);
         when(configSource.getMavenSession()).thenReturn(session);