有没有办法让Maven构建独立于网络连接?
我在持续集成环境中工作,自动化构建过程的一部分包括 Maven 托管项目的编译。
我想知道是否有一种方法可以使 Maven 构建独立于网络连接。
目前,我们已经在存储库中安装了所需的所有 jar,但问题是 Maven 会尝试检查插件更新,如果最终连接断开,这会使构建失败。
I'm working in a Continuous Integration environment and part of the automated build process includes the compilation of Maven managed projects.
What I want to know is if there is a way to make the Maven build independent of the network connection.
Currently we have the all the jar's that we need installed in the repository but the problem is that Maven tries to check for plugins updates and that makes the build fail if, eventually, the connection is down.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 -o 开关离线运行,也可以将true 添加到您的 settings.xml 中。
值得指出的是,如果 Maven 决定需要检查依赖项或插件更新,那么它在离线运行时可能会导致构建失败。 如果您将存储库设置为never 您可以避免这种情况,但您需要定期强制更新(使用 -U 和/或 -cpu)。
如果您使用存储库管理器,则可以将存储库设置为外部存储库的镜像。 这仍然涉及网络连接,但仅限于您的内部网络(或者如果存储库管理器位于您的本地计算机上,则根本没有连接)。
例如,此配置将所有对中央的调用重定向到在我的开发盒上运行的本地 Nexus 服务器:
You can either run offline with the -o switch or by adding <offline>true<offline> to your settings.xml.
It's worth pointing out though that Maven may fail the build when running offline if it decides it needs to check for dependency or plugin updates. If you set your repositories with <updatePolicy>never</updatePolicy> you can avoid this, but you'll need to force updates periodically (with -U and/or -cpu).
If you are using a repository manager, you can set your repository to be a mirror of the external repositories. This still involves a network connection, but only your internal network (or if the repository manager is on your local machine, no connection at all).
For example this config redirects all calls to central to my local Nexus server running on my development box:
使用 -o(离线)选项
use the -o (offline) option
您可以尝试安装“构建工件存储库管理器”,例如 Archiva (http://archiva.apache.org/) 在您的本地网络中。
它将作为镜像工作,因此 Maven 将尝试在本地网络而不是互联网上下载并检查更新。 你还应该构建自己的工件并在档案上使用它。
You can try installing a "Build Artifact Repository Manager" like Archiva (http://archiva.apache.org/) in you local network.
It will work as a mirror, so maven will try to download and check for updates on your local network and not over internet. Uou should also build your own artifacts and use it on archiva.