Is there a way to make the Maven build independent of the network connection?

瘦欲@ 提交于 2019-12-22 09:41:13

问题


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.


回答1:


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:

<mirrors>
  <mirror>
    <id>central-proxy</id>
    <mirrorOf>central</mirrorOf>
    <url>http://localhost/nexus/content/groups/public</url>
  </mirror>
</mirrors>



回答2:


use the -o (offline) option




回答3:


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.



来源:https://stackoverflow.com/questions/1244654/is-there-a-way-to-make-the-maven-build-independent-of-the-network-connection

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