[英]maven-dependency-plugin can't exclude test-scope dependencies
我正在使用maven-dependency-plugin:copy-dependencies将所有依赖项复制到target/dependency
录中。 我的pom.xml
是:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
插件版本是最新的: 3.1.2
(在父 pom 中定义)。
这个定义工作正常,有一个例外:它将所有测试依赖项复制到target
目录中,我只需要运行目标 jar 所需的运行时依赖项。
我尝试使用文档中描述的<excludeScope>
配置排除它:
<configuration>
<excludeScope>test</excludeScope>
</configuration>
但这会使构建失败并显示消息:
[INFO] --- maven-dependency-plugin:2.10:copy-dependencies (copy-dependencies) @ app ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.006 s
[INFO] Finished at: 2021-02-15T10:32:26+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.10:copy-dependencies (copy-dependencies) on project app: Can't exclude Test scope, this will exclude everything. -> [Help 1]
我真的不明白为什么排除测试 scope 会排除所有内容,因为在不排除test
scope 的情况下,目标目录也包含所有运行时依赖项(以及测试部门)。
排除测试依赖项可能会出现什么问题? 如何正确执行?
PS:请不要建议我在这里使用程序集或其他 fat-jar 插件,因为我故意复制依赖项 jars 用于 Docker 图像构建优化:一层用于依赖项,另一层用于 Z68995FCBF432492D15484D 依赖项,其中 DAC04 总是缓存层直到任何依赖项改变:
COPY target/dependency /usr/lib/app/lib
COPY target/${JAR_FILE} /usr/lib/app/target.jar
解决方案可能在includeScope
描述中:
Scope 包括在内。 空字符串表示所有范围(默认)。 被解释的范围是 Maven 看到的范围,而不是 pom.xml 中指定的范围。 总之:
runtime
scope 提供运行时和编译依赖项,compile
scope 给出编译、提供和系统依赖,test
(默认) scope 给出所有依赖项,provided
scope 只提供提供的依赖项,system
scope 只是给出系统依赖关系。
这意味着我会尝试使用<includeScope>runtime</includeScope>
。
排除正在测试的依赖项 scope 是使用 includeScope 运行时而不是 excludeScope 作为测试的插件文档意味着“一切”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.