gpt4 book ai didi

java - maven-dependency-plugin 不能排除测试范围依赖

转载 作者:行者123 更新时间:2023-12-04 08:06:21 25 4
gpt4 key购买 nike

我正在使用 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 中定义)。

此定义工作正常,但有一个异常(exception):它将所有测试依赖项复制到 target 中目录,我只需要运行目标 jar 所需的运行时依赖项。

我试图排除它 usgin <excludeScope>配置如 the documentation 中所述:

<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]

我真的不明白为什么排除测试范围会排除所有内容,因为不排除 test范围,目标目录也包含所有运行时依赖项(以及测试部门)。

排除测试依赖项可能有什么问题?如何正确操作?

PS:请不要建议我在这里使用程序集或其他 fat-jar 插件,因为我有意复制依赖 jar 以进行 Docker 镜像构建优化:一层用于依赖​​,另一层用于 jar,其中依赖层始终缓存直到任何依赖项更改:

COPY target/dependency  /usr/lib/app/lib
COPY target/${JAR_FILE} /usr/lib/app/target.jar

最佳答案

解决方案可能在 includeScope 中描述:

Scope to include. An Empty string indicates all scopes (default). The scopes being interpreted are the scopes as Maven sees them, not as specified in the pom. In summary:

  • runtime scope gives runtime and compile dependencies,
  • compile scope gives compile, provided, and system dependencies,
  • test (default) scope gives all dependencies,
  • provided scope just gives provided dependencies,
  • system scope just gives system dependencies.

这意味着我会尝试使用 <includeScope>runtime</includeScope> .

关于java - maven-dependency-plugin 不能排除测试范围依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66204340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com