java - 多个存储库的 Maven 设置

标签 java build repository maven-3 nexus

我在 settings.xml 中有以下内容

<mirrors>
       <mirror>
          <id>paid-jars</id>
          <name>jars with license</name>
          <url>http://url:8081/nexus/content/repositories/paidjars/</url>
          <mirrorOf>!central</mirrorOf>
      </mirror>
      <mirror>
          <id>Org-central</id>
          <name>mirror of central</name>
          <url>http://url:8081/nexus/content/repositories/central/</url>
          <mirrorOf>central</mirrorOf>
      </mirror>
  </mirrors>

在 pom.xml 我有两个 jar

  1. apache-commons.jar(我假设是从中央下载的)
  2. licensed.jar(我假设是从付费 jar 下载的)

但是当我运行 maven clean install 时,它会尝试从 Org-central 下载 license.jar。

如何让它使用付费 jar 下载?是否有可能首先进入 Org-central,如果失败,它会尝试付费 jar ?如果是这样,怎么做?我不想将 repo 条目放在 pom.xml 中


Settings.xml

<?xml version="1.0" encoding="UTF-8"?>    
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <proxies>    
    <proxy>
      <id>Proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>username</username>
      <password>******</password>
      <host>host.url</host>
      <port>8080</port>
      <nonProxyHosts>local.net|internal.com</nonProxyHosts>
    </proxy>
  </proxies>
 <mirrors>
       <mirror>
          <id>paid-jars</id>
          <name>jars with license</name>
          <url>http://url:8081/nexus/content/repositories/paidjars/</url>
          <mirrorOf>!central</mirrorOf>
      </mirror>
      <mirror>
          <id>Org-central</id>
          <name>mirror of central</name>
          <url>http://url:8081/nexus/content/repositories/central/</url>
          <mirrorOf>central</mirrorOf>
      </mirror>
  </mirrors>
  <profiles>
      <profile>
          <id>compiler</id>
          <properties>
              <JAVA_1_7_HOME>C:\Program Files (x86)\Java\jdk1.7.0_51\bin</JAVA_1_7_HOME>
          </properties>
      </profile>
  </profiles>
</settings>

最佳答案

你必须设置镜像

<mirror>
  <id>nexus</id>
  <mirrorOf>*</mirrorOf>
  <url>http://internal/nexus/content/repositories/thirdparty</url>
</mirror>

 <mirror>
  <id>google</id>
  <mirrorOf>google</mirrorOf>
  <url>http://google-maven-repository.googlecode.com/svn/repository</url>
</mirror>   

然后添加内部和外部 repo

<profile>
     <id>nexus</id>
  <repositories>

    <repository>
      <id>central</id>
      <name>central</name>
      <url>http://internal/nexus/content/repositories/thirdparty</url>
    </repository>


    <repository>
      <id>google</id>
      <name>google</name>
      <url>http://google-maven-repository.googlecode.com/svn/repository</url>
    </repository>

  </repositories>
</profile>

关于java - 多个存储库的 Maven 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25424338/

相关文章:

java - 如何在java中捕获桌面屏幕图像?

java - 远程接口(interface)无法转换为 EJB 容器

android - Cordova 找不到模块

c++ - 与 C++ 库链接时,如何在 OCaml 编译中抑制 g++ 弃用警告?

java - ArrayList 的 containsAll 返回错误值

java - 我可以避免使用多个计时器吗?

Python 3.2 - uWSGI 进程出现段错误

c# - 我应该在 DDD 中的什么地方进行独特的检查?

c# - Entity Framework 在 View 上抛出函数错误

Git repo 同步错误 : branch XYZ is published (but not merged) and is now 1 commits behind