简体   繁体   English

如何防止Maven检查我未在settings.xml文件中列出的存储库中的更新?

[英]How can I prevent Maven from checking for updates from repositories that I don't list in my settings.xml file?

In my settings.xml file I have listed repositories that I want Maven to use (see the file below). 在我的settings.xml文件中,我列出了我希望Maven使用的存储库(请参阅下面的文件)。 These repositories are located in the build machine and I am working this way to prevent a build fail when there's is no Internet connection in the build machine. 这些存储库位于构建计算机中,我正在以这种方式工作,以防止在构建计算机中没有Internet连接时构建失败。

The problem is that Maven automatically looks for updates in the central repository (and possibly from other non-listed repositories) during the build. 问题是Maven在构建期间自动在中央存储库(以及可能来自其他未列出的存储库)中查找更新。 Is there a way to prevent this behaviour? 有没有办法防止这种行为?

 ...
<profile>
  <id>myProfile</id>
  <repositories>
    <repository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <updatePolicy>never</updatePolicy>
      </snapshots>
      <id>myRepo</id>
      <url>file://${my.home}/maven/.m2/repository</url>
      <layout>default</layout>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <updatePolicy>never</updatePolicy>
      </snapshots>
      <id>myRepo</id>
      <url>file://${my.home}/maven/.m2/repository</url>
      <layout>default</layout>
    </pluginRepository>
  </pluginRepositories>
</profile>
...

Note: Using the offline option (eg -o flag) is not an option for me. 注意:使用离线选项(例如-o标志)对我来说不是一个选项。 What I really want is Maven to use only the repositories that I list in my settings.xml file. 我真正想要的是Maven只使用我在settings.xml文件中列出的存储库。

Every Maven project inherits the configuration for the central repository from the Maven Super POM . 每个Maven项目都从Maven Super POM继承了中央存储库的配置。 You can use Maven's mirrors feature to redirect calls to central to your preferred repository. 您可以使用Maven的镜像功能将呼叫重定向到中央到您首选的存储库。 You do this by adding some configuration to your settings.xml like this: 您可以通过向settings.xml添加一些配置来执行此操作,如下所示:

<settings>
...
  <mirrors>
    <mirror>
      <id>central-proxy</id>
      <mirrorOf>central</mirrorOf>
      <url>http://myrepository/releases</url>
    </mirror>
  </mirrors>
  ..
</settings>

This configuration can either be put in your user settings (${user.home}/.m2/settings.xml) or global settings ({$M2_HOME}/conf/settings.xml). 此配置可以放在用户设置($ {user.home} /.m2 / settings.xml)或全局设置({$ M2_HOME} /conf/settings.xml)中。

Set your desired repositories as a mirror of everything else. 将您想要的存储库设置为其他所有存储库的镜像。

More details: http://maven.apache.org/guides/mini/guide-mirror-settings.html 更多细节: http//maven.apache.org/guides/mini/guide-mirror-settings.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM