简体   繁体   English

使用Maven Central作为辅助存储库

[英]Use Maven Central as a secondary repository

My organization hosts its own maven repository (JFrog) and all dev machines are already configured to always look into the enterprise maven repository for all Java jars. 我的组织拥有自己的Maven存储库(JFrog),并且所有开发机器都已配置为始终查看所有Java jar的企业Maven存储库。

Now sometimes I am learning new technology on my own and the jar download will sometimes fail because the enterprise maven central does not have those jars 现在有时我自己学习新技术,并且jar下载有时会失败,因为企业maven Central没有这些jar

[ERROR] Failed to execute goal on project JooqTest: Could not resolve 
dependencies for project com.abhi:JooqTest:jar:1.0-SNAPSHOT: The following 
artifacts could not be resolved: org.jooq:jooq:jar:3.7.1, org.jooq:jooq-
meta:jar:3.7.1, org.jooq:jooq-codegen:jar:3.7.1: Failure to find 
org.jooq:jooq:jar:3.7.1 in http://artifactory.foo.com/artifactory/all-repos was 
cached in the local repository, resolution will not be reattempted until the 
update interval of foo-artifactory-as-mirror has elapsed or updates are forced -> 
[Help 1]

Can I configure Maven on my machine so it will first look for jars in the organization Maven repository, and if it doesn't find it there, then look into Maven central? 我可以在我的机器上配置Maven,以便它首先在组织Maven存储库中查找jars,如果在那里找不到jar,然后查看Maven Central?

The most desirable outcome would likely be to have them add any other repository server as a proxied server. 最理想的结果可能是让他们将任何其他存储库服务器添加为代理服务器。

From the jfrog page: jfrog页面:

Overview
In corporate environments it is often required to go through a proxy server to access remote resources.
Artifactory supports several types of network proxy including NTLMv2.

This is how we have our work environment and build scripts setup which keeps our build script clean and only have a single remote repo listed. 这就是我们的工作环境和构建脚本设置的方式,该设置可保持构建脚本干净,并且仅列出一个远程回购。

I bet your current settings.xml (either under MVN_DIR/conf , or under your HOME/.m2 ) has setup your enterprise repo as mirror of central. 我敢打赌,您当前的settings.xml(在MVN_DIR/conf下或在HOME/.m2 )已将您的企业存储库设置为集中式镜像。

Normally, assuming you have internet connection, you can add extra remote repositories in your settings.xml by: (copied from https://maven.apache.org/settings.html ) 通常,假设您已连接互联网,则可以通过以下方式在settings.xml添加额外的远程存储库(从https://maven.apache.org/settings.html复制)

  <profiles>
    <profile>
      ...
      <repositories>
        <repository>
          <id>codehausSnapshots</id>
          <name>Codehaus Snapshots</name>
          <releases>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
          </snapshots>
          <url>http://snapshots.maven.codehaus.org/maven2</url>
          <layout>default</layout>
        </repository>
      </repositories>
      <pluginRepositories>
        ...
      </pluginRepositories>
      ...
    </profile>
  </profiles>

You may also want to setup proxy if your company require you to connect to internet thru proxy. 如果您的公司要求您通过代理连接到Internet,则可能还需要设置代理。 Related info can be found in above-mentioned URL 相关信息可以在上述网址中找到

If you are desperate and can't get your 'enterprise admin' to configure what you need on the company-wide repo for whatever reason, you could try running your own Maven repository proxy (eg Nexus, Artifactory) on your own machine (or localized to your team) that proxies both Central and your company-wide repo. 如果您绝望而又出于某种原因而无法让“企业管理员”配置公司范围内的仓库中所需的东西,则可以尝试在自己的计算机(或Nexus)上运行自己的Maven存储库代理(例如Nexus,Artifactory)本地化),可以同时代理Central和整个公司的存储库。 Then point your settings.xml to your local repo proxy instead of the company-wide one. 然后将您的settings.xml指向本地回购代理,而不是整个公司范围内的代理。 You might want to do this in a profile so that you can switch between the standard corporate configuration and your proxy easily. 您可能希望在配置文件中执行此操作,以便可以在标准公司配置和代理之间轻松切换。

This assumes that you can download JARs from central, and are not blocked by corporate proxy server, etc. 这假定您可以从中央下载JAR,并且不受公司代理服务器等的阻止。

A better situation would be to have a talk with your repo manager and negotiate, perhaps get an 'experimentation' repo that proxies central, and only do the personal proxy thing if absolutely necessary. 更好的情况是与您的回购经理进行讨论并进行谈判,也许会得到一个“实验”回购来代理中心,并且仅在绝对必要时才进行个人代理。

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

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