Maven无法从存储库获取SNAPSHOT构建

Kri*_*ris 27 java maven-2 artifactory

我们的内部存储库(Artifactory)现在包含稳定版本以及内部库的SNAPSHOT版本.

对于稳定版本,从存储库中下载任何内容从未出现过问题.

但是,当我添加-SNAPSHOT时,Maven声称无法找到依赖项,即使它最明确地存储在存储库中.

如果我在本地构建和部署依赖项(即进入我的本地存储库),所有工作都正常.

基本上,这有效:

<dependency>
  <groupId>com.example</groupId>
  <artifactId>ourlibrary</artifactId>
  <version>1.0.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

这不是:

<dependency>
  <groupId>com.example</groupId>
  <artifactId>ourlibrary</artifactId>
  <version>1.0.1-SNAPSHOT</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

即使两个版本都以相同的方式构建并且(正如我可能告诉的)正确地部署到存储库.

错误:

Missing:
----------

1) com.example:ourlibrary:jar:1.0.1-SNAPSHOT,

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=com.example -DartifactId=ourlibrary -Dversion=1.0.1-SNAPSHOT, -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:
      mvn deploy:deploy-file -DgroupId=com.example -DartifactId=ourlibrary -Dversion=1.0.1-SNAPSHOT, -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
        1) com.example:product:war:2.0.0-SNAPSHOT
        2) com.example:ourlibrary:jar:1.0.1-SNAPSHOT,
Run Code Online (Sandbox Code Playgroud)

虽然这听起来类似于这个问题,但到达那里的决议并不适用于我的情况.

任何有关这个问题的见解将不胜感激.

编辑

使用-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)
Run Code Online (Sandbox Code Playgroud)

Joh*_*int 14

想到两个想法:

  1. 内部存储库中用于工件的路径结构不正确.我建议使用-X参数运行maven命令.它将显示maven尝试下载文件.获取将您的存储库作为URL的行,并尝试自己查找.

    路径应该是这样的

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

  2. 您没有将存储库作为存储库包含在pom.xml中

  • 我想我已经解释过了.对于稳定版本,Maven将默认为"central",我的镜像设置会重定向到我们的存储库.对于SNAPSHOT构建,没有默认值(因为中心不处理它们)并且在没有POM指定repo(*执行*处理SNAPSHOT构建)的情况下,它甚至会在没有尝试查找的情况下失败. (16认同)
  • 我没有在POM中声明repo,而是在maven设置中指定我们的repo是一个通用(*)镜像.这应该不够(对于稳定版本来说肯定是足够的)?向POM添加显式声明确实可以解决问题. (2认同)

kev*_*ohr 13

通常,您有来自版本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>
Run Code Online (Sandbox Code Playgroud)