maven无法从中央存储库下载工件

qncylg1j  于 2021-07-08  发布在  Java
关注(0)|答案(2)|浏览(350)

我有两个私人jfrog存储库。一个存储库处理发布,另一个处理快照。下面是我在我的文章中如何定义的 settings.xml 文件。

<settings>

    <activeProfiles>
        <activeProfile>default</activeProfile>
    </activeProfiles>

    <servers>
        <server>
            <id>central</id>
            <username>private-repo-username</username>
            <password>private-repo-password</password>
        </server>
        <server>
            <id>snapshots</id>
            <username>private-repo-username</username>
            <password>private-repo-password</password>
        </server>
    </servers>

    <profiles>
        <profile>
            <id>default</id>
            <repositories>
                <repository>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <id>central</id>
                    <name>a0d2olsx0t222-artifactory-primary-0-releases</name>
                    <url>https://my-private-repo.jfrog.io/artifactory/libs-release</url>
                </repository>
                <repository>
                    <id>snapshots</id>
                    <name>a0d2olsx0t222-artifactory-primary-0-snapshots</name>
                    <url>https://my-private-repo.jfrog.io/artifactory/libs-snapshot</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
        </profile>
    </profiles>
</settings>

我的多模块maven项目中的多个内部依赖项出现以下错误:

[ERROR] Failed to execute goal on project platform-utils: Could not resolve dependencies for project
design.colspalinva:platform-utils:jar:2.2.1-SNAPSHOT: The following artifacts could not be resolved: 
com.maxmind.geoip2:geoip2:jar:2.12.0, org.apache.ant:ant:jar:1.10.5: Could not find artifact 
com.maxmind.geoip2:geoip2:jar:2.12.0 in central (https://my-private-repo.jfrog.io/artifactory/libs-
release) -> [Help 1]

从外观上看,maven似乎并没有试图联系官方maven central repo来获取这些依赖项,而是在我的私有存储库上失败了。我的印象是,如果私有存储库不包含特定的工件,它将尝试联系maven central。
从maven central下载我的spring依赖项没有问题。

ecr0jaav

ecr0jaav1#

您共享的maven settings.xml配置似乎还可以。您正在重写maven的内置中央和快照存储库,这是确保maven在默认情况下向artifactory发送请求的正确方法。
如另一个答案中所建议的,添加mirror any设置意味着除了覆盖内置maven存储库之外,还可以使用mirror any设置通过artifactory将所有请求重定向到maven存储库,包括在pom中定义的插件和第三方依赖项。
根据您共享的日志,maven确实尝试通过artifactory解析工件-https://my-private-repo.jfrog.io/artifactory/libs-release
这个问题似乎与artifactory中特定工件的解析有关。
我假设libs发行版是一个虚拟maven存储库,并且它至少包含一个指向jcenter或maven central的远程maven存储库(如果不是,请从查看maven存储库开始)。
调试问题:
(1) 尝试使用curl或web浏览器直接从artifactory解析工件,例如:

curl -Uuser:pass https://my-private-repo.jfrog.io/artifactory/libs-release/com/maxmind/geoip2/geoip2/2.12.0/geoip2-2.12.0.jar

(2) 如果您成功地解析了工件,这意味着工件配置正确,maven应该能够解析。如果不是,请尝试查找执行跟踪的原因,例如:

curl -Uuser:pass https://my-private-repo.jfrog.io/artifactory/libs-release/com/maxmind/geoip2/geoip2/2.12.0/geoip2-2.12.0.jar?trace
w7t8yxp5

w7t8yxp52#

如果您想将对central的所有访问从maven重定向到您自己的存储库管理器,则必须配置 settings.xml 具体如下:

<! language:language-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
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">
   <mirrors>
      <mirror>
         <id>nexus</id>
         <mirrorOf>*</mirrorOf>
         <url>http://IP:PORT/repository/repo</url>
      </mirror>
   </mirrors>
   <profiles>
      <profile>
         <id>nexus</id>
         <repositories>
            <repository>
               <id>central</id>
               <url>http://central</url>
               <releases>
                  <enabled>true</enabled>
                  <updatePolicy>never</updatePolicy>
                  <checksumPolicy>fail</checksumPolicy>
               </releases>
               <snapshots>
                  <enabled>true</enabled>
                  <updatePolicy>always</updatePolicy>
                  <checksumPolicy>fail</checksumPolicy>
               </snapshots>
            </repository>
         </repositories>
         <pluginRepositories>
            <pluginRepository>
               <id>central</id>
               <url>http://central</url>
               <releases>
                  <enabled>true</enabled>
                  <updatePolicy>never</updatePolicy>
                  <checksumPolicy>fail</checksumPolicy>
               </releases>
               <snapshots>
                  <enabled>true</enabled>
                  <updatePolicy>always</updatePolicy>
                  <checksumPolicy>fail</checksumPolicy>
               </snapshots>
            </pluginRepository>
         </pluginRepositories>
      </profile>
   </profiles>
   <activeProfiles>
      <!--make the profile active all the time -->
      <activeProfile>nexus</activeProfile>
   </activeProfiles>
</settings>

相关问题