Skip to content

Commit

Permalink
[MASSEMBLY-1008] Wrong use of dependency scopes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cstamas committed Nov 15, 2023
1 parent a700d0e commit 23442c0
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 15 deletions.
13 changes: 3 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ under the License.
</contributors>

<prerequisites>
<maven>${mavenVersion}</maven>
<maven>3.2.5</maven>
</prerequisites>

<scm>
Expand All @@ -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>

Expand Down Expand Up @@ -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>
Expand Down
68 changes: 68 additions & 0 deletions src/it/projects/dependency-sets/massembly-1008/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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>
48 changes: 48 additions & 0 deletions src/it/projects/dependency-sets/massembly-1008/verify.groovy
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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;
Expand Down Expand Up @@ -123,7 +124,7 @@ public void testAddDependencySet_ShouldInterpolateDefaultOutputFileNameMapping()
.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);
Expand Down Expand Up @@ -210,7 +211,7 @@ public void testAddDependencySet_ShouldNotAddDependenciesWhenProjectIsStubbed()
.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);
Expand Down Expand Up @@ -268,7 +269,7 @@ private void verifyOneDependencyAdded(final String outputLocation, final boolean
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);
Expand Down Expand Up @@ -441,7 +442,6 @@ public void useDefaultExcludes() throws Exception {
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);

Expand All @@ -453,7 +453,7 @@ public void useDefaultExcludes() throws Exception {
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);
Expand Down

0 comments on commit 23442c0

Please sign in to comment.