如何从包阶段中排除maven测试范围?

时间:2015-02-17 13:55:34

标签: java maven

我正在mvn package上的分隔符文件夹中收集所有依赖项库,如下所示:

    <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>${maven.copy.plugin}</version>
        <executions>
            <execution>
                <id>copy-dependencies</id>
                <phase>package</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.build.directory}/lib/</outputDirectory>
                </configuration>
            </execution>
        </executions>
    </plugin>

问题:这还包括<scope>test</scope>个库。 我该如何排除这些库?

1 个答案:

答案 0 :(得分:18)

使用includeScope仅包含runtime范围内的依赖项:

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>${maven.copy.plugin}</version>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/lib/</outputDirectory>
                <includeScope>runtime</includeScope>
            </configuration>
        </execution>
    </executions>
</plugin>

显然,<excludeScope>test</excludeScope>似乎不受支持,因为test范围涵盖所有依赖项(https://issues.apache.org/jira/browse/MDEP-85)。