创建一个封闭的 Maven 构建

Create an hermetic Maven build

我正在准备一个他们可能没有 Internet 连接的研讨会。因此,我想提供项目的每个 dependency/plugin,以便与会者可以完全离线处理它。

我有一个基本的 Maven 项目,其中包含一些依赖项和两个插件。

首先,我创建了一个备用本地存储库:

mvn -Dmaven.repo.local=dependencies dependency:go-offline

然后,我希望以下命令能够 运行 正常,但事实并非如此!我提到一些缺少的插件在 maven 中心或 maven 发行版中不可用:

mvn -o -Dmaven.repo.local=dependencies package

失败并显示以下错误消息:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources (default-resources) on project XXX: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources failed: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: The following artifacts could not be resolved: org.apache.maven:maven-profile:jar:2.0.6, org.apache.maven:maven-repository-metadata:jar:2.0.6, org.apache.maven:maven-plugin-registry:jar:2.0.6, classworlds:classworlds:jar:1.1-alpha-2: Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact org.apache.maven:maven-profile:jar:2.0.6 has not been downloaded from it before.

知道如何在创建备用本地存储库时获取这些缺失的位吗?提前致谢!

文档似乎表明您需要 运行:

  mvn dependency:resolve-plugins

之前go-offline

可以试试吗?

参见:https://people.apache.org/~aramirez/maven-dependency-plugin/go-offline-mojo.html

基于这个问题在plugin's Jira这个问题还是没有解决。 到目前为止最好的解决方法是使用自定义存储库在线打包项目一次。

mvn -Dmaven.repo.local=dependencies dependency:go-offline

然后

mvn -Dmaven.repo.local=dependencies package

最后

mvn -Dmaven.repo.local=dependencies -o package

如果你的研讨会比部署更进一步,你应该检查下一个目标 运行 离线也很好!

你能为你的打包使用的每个插件声明 pluginManagement 吗?这应该会在调用 dependency:go-offline 时启用下载。

(此外,这将提高构建的稳定性,因为您可以确定更改 Maven 版本不会更改插件版本)

你能确认这有效吗? (现在,我有改进的想法,但至少在几个月前不会可用...)