xyakimo1
xyakimo1

Reputation: 11

Why does test scope in maven-assembly-plugin also include the provided scope?

If a dependencySet's scope is set to test, dependencies with the provided scope are also added, while I'd expect that provided-scoped dependencies are included only if explicitly specified.

My question is not about how to avoid such behavior, but why this happens. What are the reasons behind this? Is it documented?

Minimal reproducible example:

pom.xml

    <dependencies>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-console</artifactId>
            <version>1.10.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcpkix-jdk18on</artifactId>
            <version>1.77</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.7.1</version>
                <executions>
                    <execution>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/assembly/assembly.xml</descriptor>
                            </descriptors>
                            <finalName>maven-assembly-plugin-scopes</finalName>
                        </configuration>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>

                </executions>
            </plugin>
        </plugins>
    </build>

assembly.xml

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.2.0 https://maven.apache.org/xsd/assembly-2.2.0.xsd">
    <id>example-assembly</id>
    <formats>
        <format>jar</format>
    </formats>

    <includeBaseDirectory>false</includeBaseDirectory>

    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <unpack>true</unpack>
            <scope>test</scope>
        </dependencySet>
    </dependencySets>

</assembly>

Like this, BouncyCastle is added to the assembled JAR.

Upvotes: 0

Views: 40

Answers (0)

Related Questions