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

发布于 2024-09-30 18:36:51 字数 2262 浏览 9 评论 0原文

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

对于稳定的构建,从来不存在从存储库下载任何内容的问题。

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

如果我在本地构建并部署依赖项(即到我的本地存储库中),则一切正常。

基本上,这是可行的:

<dependency>
  <groupId>com.example</groupId>
  <artifactId>ourlibrary</artifactId>
  <version>1.0.0</version>
</dependency>

而这不行:

<dependency>
  <groupId>com.example</groupId>
  <artifactId>ourlibrary</artifactId>
  <version>1.0.1-SNAPSHOT</version>
</dependency>

即使两个版本都是以相同的方式构建并正确部署(据我所知)到存储库的。

错误:

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,

虽然这听起来类似于这个问题,但到达的解决方案并不适用于我的案例。

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

编辑

使用 -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)

Our internal repository (Artifactory) now contains both the stable builds as well as SNAPSHOT versions of our internal libraries.

For stable builds there has never been a problem of downloading anything from the repository.

However, when I add a -SNAPSHOT, Maven claims to be unable to find the dependency, even though it is most definitely in the repository.

If I build and deploy the dependency locally (i.e. into my local repo) all works normally.

Basically, this works:

<dependency>
  <groupId>com.example</groupId>
  <artifactId>ourlibrary</artifactId>
  <version>1.0.0</version>
</dependency>

and this doesn't:

<dependency>
  <groupId>com.example</groupId>
  <artifactId>ourlibrary</artifactId>
  <version>1.0.1-SNAPSHOT</version>
</dependency>

Even though both versions were built the same way and deployed (as far as I can possibly tell) correctly to the repository.

The error:

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,

While this sounds similar to this question, the resolution arrived at there does not apply to my case.

Any insights into this issue would be greatly appreciated.

Edit

Running with -X (as John V. suggested) revealed the following:

[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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨小沫ゞ 2024-10-07 18:36:51

我想到了两个想法:

  1. 你内部的路径结构
    您的工件的存储库是
    不正确。我建议运行
    带有 -X 参数的 Maven 命令。它
    将显示 Maven 的尝试
    下载文件。获取线路
    以您的存储库作为 url
    并尝试自己寻找。

    路径应该类似于

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

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

Two thoughts come to mind:

  1. The path structure in your internal
    repository for your artifact is
    incorrect. I suggest running the
    maven command with -X parameter. It
    will display the maven's attempt at
    downloading the files. Get the line
    that has your repository as the url
    and try and look for it yourself.

    The path should look like

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

  2. You didnt include your repository as
    a repository in your pom.xml
哎呦我呸! 2024-10-07 18:36:51

通常,您有一个与发布 url 不同的快照 url。只是同一存储库中的不同路径,但在 pom.xml 中列为单独的存储库。用于快照的需要启用快照,用于发布的则禁用快照:

<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>

Typically you have a separate snapshots url from releases url. Just different paths in the same repository, but listed as separate repositories in the pom. The one for snapshots needs to have snapshots enabled, and the one for releases has snapshots disabled:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文