Java Maven无法从存储库获取快照生成

Java Maven无法从存储库获取快照生成,java,maven-2,artifactory,Java,Maven 2,Artifactory,我们的内部存储库(Artifactory)现在包含内部库的稳定版本和快照版本 对于稳定的构建,从存储库下载任何东西都不会有问题 然而,当我添加快照时,Maven声称无法找到依赖项,即使它肯定在存储库中 如果我在本地构建并部署依赖项(即,将其部署到本地repo中),所有这些都可以正常工作 基本上,这是可行的: <dependency> <groupId>com.example</groupId> <artifactId>ourlibrary&

我们的内部存储库(Artifactory)现在包含内部库的稳定版本和快照版本

对于稳定的构建,从存储库下载任何东西都不会有问题

然而,当我添加快照时,Maven声称无法找到依赖项,即使它肯定在存储库中

如果我在本地构建并部署依赖项(即,将其部署到本地repo中),所有这些都可以正常工作

基本上,这是可行的:

<dependency>
  <groupId>com.example</groupId>
  <artifactId>ourlibrary</artifactId>
  <version>1.0.0</version>
</dependency>
虽然这听起来类似于问题,但在那里达成的决议并不适用于我的情况

对此问题的任何见解都将不胜感激

编辑

使用-X运行(正如John V.所建议的)揭示了以下内容:

[DEBUG] Skipping disabled repository central
[DEBUG] ourlibrary: using locally installed snapshot
[DEBUG] Skipping disabled repository central
[DEBUG] Using mirror: http://repo.example.com/repo (id: repo.example.com)
[DEBUG] Artifact not found - using stub model: Unable to download the artifact from any repository

  com.example:ourlibrary:pom:1.0.1-SNAPSHOT

from the specified remote repositories:
  repo.example.com (http://repo.example.com/repo)


[DEBUG] Using defaults for missing POM com.example:ourlibrary:pom:1.0.1-SNAPSHOT:compile
[DEBUG]   com.example:ourlibrary:jar:1.0.1-SNAPSHOT:compile (selected for compile)

我想到两个想法:

  • 您的内部数据库中的路径结构 您的工件的存储库是 不对。我建议运行 带有-X参数的maven命令。信息技术 将显示maven试图 下载文件。接电话 将您的存储库作为url 试着自己去找

    路径应该是这样的

    /com/example/ourlibrary/1.0.1/ourlibrary-1.0.1-SNAPSHOT.jar

  • 您没有将存储库作为 pom.xml中的存储库

  • 通常,您有一个独立于发布url的快照url。同一存储库中的不同路径,但在pom中作为单独的存储库列出。用于快照的一个需要启用快照,用于发布的一个需要禁用快照:

    <repositories>
            <repository>
                <id>central</id>
                <url>
                    http://<releases-url>
                </url>
                **<snapshots>
                    <enabled>false</enabled>
                </snapshots>**
            </repository>
    
            <repository>
                <id>snapshots</id>
                <url>
                    http://<snapshots-url>
                </url>
                <snapshots>
                    **<enabled>true</enabled>**
                    <!-- never, daily, interval:X (where X is in minutes) or always -->
                    <!--<updatePolicy>daily</updatePolicy> -->
                </snapshots>
                <releases>
                    <enabled>false</enabled>
                </releases>
            </repository>
        </repositories>
    
    
    中心的
    http://
    **
    假的
    **
    快照
    http://
    **真的**
    假的
    
    我没有在POM中声明回购协议,而是在maven设置中指定我们的回购协议是一个通用(*)镜像。这难道还不够吗(对于稳定的构建来说当然足够了)?向POM添加显式声明似乎确实解决了这个问题。不幸的是,我没有对存储库的settings.xml做太多工作。我将它们包含在父级pom中,因此任何刚开始使用的开发人员都不必担心settings.xml,以防存储库必须更改(它实际上为我们更改了),我想我已经解释清楚了这一点。对于稳定的构建,Maven将默认为“central”,我的镜像设置将其重定向到我们的存储库。对于快照生成,没有默认设置(因为central不处理它们),并且在POM未指定repo(处理快照生成)的情况下,它只会失败,甚至不会尝试查找它。尽管您应该注意,这在Maven settings.xml文件的profiles部分下是有效的。我们将它保存在所有项目继承的master/parent pom文件中。这样,开发人员就不必在settings.xml文件中配置它。xml主要用于特定于机器或用户的内容,项目的所有开发人员通常都应该使用相同的存储库。虽然您可以将存储库放在settings.xml文件中,但我认为这是一种例外情况,而不是正常情况。非常奇怪,我可以在没有此文件的情况下部署快照,但无法下载已部署的快照。配置文件设置工作正常。@Kris这仍然是从apache.org central下载的,直到我添加了指向发布URL的所有内容的镜像标记,以及指向Raghuram反复试验发现的快照URL的快照镜像,@Betlista“存储库”标记部分控制下拉到构建的依赖项。您构建和部署的工件将转到“distributionManagement”标记部分告诉它们的位置。
    [DEBUG] Skipping disabled repository central
    [DEBUG] ourlibrary: using locally installed snapshot
    [DEBUG] Skipping disabled repository central
    [DEBUG] Using mirror: http://repo.example.com/repo (id: repo.example.com)
    [DEBUG] Artifact not found - using stub model: Unable to download the artifact from any repository
    
      com.example:ourlibrary:pom:1.0.1-SNAPSHOT
    
    from the specified remote repositories:
      repo.example.com (http://repo.example.com/repo)
    
    
    [DEBUG] Using defaults for missing POM com.example:ourlibrary:pom:1.0.1-SNAPSHOT:compile
    [DEBUG]   com.example:ourlibrary:jar:1.0.1-SNAPSHOT:compile (selected for compile)
    
    <repositories>
            <repository>
                <id>central</id>
                <url>
                    http://<releases-url>
                </url>
                **<snapshots>
                    <enabled>false</enabled>
                </snapshots>**
            </repository>
    
            <repository>
                <id>snapshots</id>
                <url>
                    http://<snapshots-url>
                </url>
                <snapshots>
                    **<enabled>true</enabled>**
                    <!-- never, daily, interval:X (where X is in minutes) or always -->
                    <!--<updatePolicy>daily</updatePolicy> -->
                </snapshots>
                <releases>
                    <enabled>false</enabled>
                </releases>
            </repository>
        </repositories>