gpt4 book ai didi

maven - mvn 依赖 :go-offline doesn't download the requirements for maven-surefire-plugin

转载 作者:行者123 更新时间:2023-12-04 17:31:45 25 4
gpt4 key购买 nike

我正在尝试在 docker 中构建一个开源项目并希望节省花费在构建上的时间,所以我尝试使用 mvn dependency:go-offline可以 下载 maven-surefire-plugin 本身。

之后运行 mvn -o clean package 会产生

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test (default-test) on project oxalis-api: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test failed: Plugin org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4 or one of its dependencies could not be resolved: Cannot access apache.snapshots (http://repository.apache.org/snapshots/) in offline mode and the artifact org.codehaus.plexus:plexus-utils:jar:1.1 has not been downloaded from it before. -> [Help 1]

(我启用了快照存储库,因为 maven-dependency-plugin 在多模块项目中存在严重问题)

POM包括

        <pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</pluginManagement>

并且如上所述,在下线后,该插件本身确实存在于我的存储库中。

最佳答案

看来你的maven本地仓库使用了legacy结构,详情here .所以目标dependency:go-offline在legacy模式下准备了repository,那么构建package的实际目标是找不到依赖的,因为它使用的是default模式。

因此对于您的特定场景,您可以使用以下命令以批处理方式下载依赖项和插件:

mvn dependency:resolve-plugins dependency:go-offline -B 

您可以使用以下方式进行构建,包括离线、批处理和遗留本地存储库选项:

mvn package -o -llr -B

提示:如果您在构建中需要在主 pom 中未明确定义的其他插件或依赖项,例如您在构建过程中添加的插件或依赖项(即 clover、allure、pact 等),您可以使用以下方法预下载命令:

mvn dependency:get -Dartifact=org.openclover:clover-maven-plugin:4.4.1 -B

提示 2:如果您在离线时遇到问题并且没有获取依赖项,可能是因为您在下载依赖项和构建项目时有不同的 maven 设置。可以考虑删除本地仓库里面的maven-metadata*.xml_*.repositories,可以这样用:

find ~/.m2/repository -name 'maven-metadata*.xml' | xargs -n1 rm
find ~/.m2/repository -name '_*.repositories' | xargs -n1 rm

关于maven - mvn 依赖 :go-offline doesn't download the requirements for maven-surefire-plugin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58972874/

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