首页 文章

maven为某些依赖设置另一个存储库

提问于
浏览
4

我有Maven2项目 . 除了一个之外的所有依赖项都从公共存储库http://repo.maven.apache.org/maven2/下载 .

但我有1个依赖项,我需要从内部公司的存储库下载(我们使用Sonatype Nexus存储此依赖项) .

另外,我不想在我的内部仓库上创建公共仓库的完整副本 .

此刻我在pom.xml中:

<url>http://maven.apache.org</url>

<repositories>
    <repository>
        <id>thirdparty</id>
        <url>http://<my_nexus_server_ip>:8081/nexus/content/repositories/thirdparty</url>
    </repository>
</repositories>

因此,在构建期间,我看到了很多垃圾邮件(在这种情况下,第一行是垃圾邮件):

Downloading: http://<my_nexus_server_ip>:8081/nexus/content/repositories/thirdparty/ant/ant/1.6.5/ant-1.6.5.pom
Downloading: http://repo.maven.apache.org/maven2/ant/ant/1.6.5/ant-1.6.5.pom
Downloaded: http://repo.maven.apache.org/maven2/ant/ant/1.6.5/ant-1.6.5.pom (861 B at 3.2 KB/sec)

我想清楚地指出Maven对于它必须使用内部存储库的依赖,并忽略它用于其他依赖项(并指出其他依赖项Maven2必须使用公共存储库) .

你能帮忙在Maven中实现这样的行为吗?

提前致谢!

2 回答

  • 1

    根据this answer,无法为某些声明的依赖项设置特定的存储库 .

  • -1

    您需要在Nexus中配置公共存储库组,以便在Maven构建中使用唯一的一个,如下所示:

    <settings>
      <mirrors>
        <mirror>
          <!--This sends everything else to /public -->
          <id>nexus</id>
          <mirrorOf>*</mirrorOf>
          <url>http://localhost:8081/nexus/content/groups/public</url>
        </mirror>
      </mirrors>
      <profiles>
        <profile>
          <id>nexus</id>
          <!--Enable snapshots for the built in central repo to direct -->
          <!--all requests to nexus via the mirror -->
          <repositories>
            <repository>
              <id>central</id>
              <url>http://central</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
            </repository>
          </repositories>
         <pluginRepositories>
            <pluginRepository>
              <id>central</id>
              <url>http://central</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
            </pluginRepository>
          </pluginRepositories>
        </profile>
      </profiles>
      <activeProfiles>
        <!--make the profile active all the time -->
        <activeProfile>nexus</activeProfile>
      </activeProfiles>
    </settings>
    

    您必须在nexus中设置一个单独的存储库,就像您描述了一个名为 ThirdParty 的存储库,并将此存储库添加到公共存储库组的配置中 . 此外,您需要将一个依赖项上载到该特定存储库中 . 除此之外,您还必须使用 releaseSNAPSHOT 存储库,这意味着您需要在公司主pom文件中相应地配置您的distributionManagement .

相关问题