Create an hermetic Maven build

穿精又带淫゛_ 提交于 2020-01-05 07:16:18

问题


I'm preparing a workshop where they may be no Internet connection. Because of that, I'd like to provide every dependency/plugin of the project, so attendees can work on it, completely offline.

I've got a basic Maven project with some dependencies and two plugins.

First, I created an alternate local repository:

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

Then, I expected the following command to run fine, but it doesn't! And I some mentioned missing plugins are not available in maven central or within the maven distribution:

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

This fail with the following error message:

[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.

Any idea how to get these missing bits while creating an alternate local repo? Thanks in advance!


回答1:


Based on this issue in the plugin's Jira this problem is still not resolved. The best work around so far is to package the project online once, using the custom repository.

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

then

mvn -Dmaven.repo.local=dependencies package

and finally

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

If your workshop go farther than deploy, you should check that next goals run fine offline too!




回答2:


can you declare pluginManagement for every plugin that is used by your packaging? That should enable downloading when dependency:go-offline is called.

(in addition, this will improve stability for your build, since you'll be sure that changing Maven version won't change plugins versions)

Can you confirm this works? (now, I have ideas to improve this, but won't be available before a few months at least...)




回答3:


The documentation seems to suggest that you need to run:

  mvn dependency:resolve-plugins

Before go-offline

Could you try it?

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



来源:https://stackoverflow.com/questions/43227202/create-an-hermetic-maven-build

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!