有没有办法让Maven自动下载快照版本?

发布于 2024-12-09 11:04:09 字数 1339 浏览 0 评论 0原文

所以我有一个项目依赖于另一个项目的快照版本。依赖关系是:

<dependency>
  <groupId>org.oop</groupId>
  <artifactId>oop</artifactId>
  <version>0.9.9-SNAPSHOT</version>
</dependency>

对于 oop 项目,我确实执行了“mvn clean 部署”,因此快照版本应该位于 Maven 中央存储库中的某个位置。但是,当我执行 mvn clean install 时,无法解决上面的快照依赖项,我得到以下信息:

Missing:

1) org.oop:oop:jar:0.9.9-SNAPSHOT

尝试从项目网站手动下载文件。

然后,使用以下命令安装它: mvn install:install-file -DgroupId=org.oop -DartifactId=oop -Dversion=0.9.9-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file

或者,如果您托管自己的存储库,则可以部署该文件那里: mvn 部署:部署文件 -DgroupId=org.oop -DartifactId=oop -Dversion=0.9.9-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

< strong>有没有办法让maven自动下载快照?我一定在这里遗漏了一些东西。

编辑1:在我的settings.xml中,我有:

   <server>
      <id>sonatype-nexus-snapshots</id>
      <username>XXXXXX</username>
      <password>XXXXXX</password>
    </server>

    <server>
      <id>sonatype-nexus-staging</id>
      <username>XXXXXX</username>
      <password>XXXXXX</password>
    </server>

编辑2: 在此处输入图像描述

So I have a project that depends on a snapshot version of another project. The dependency is:

<dependency>
  <groupId>org.oop</groupId>
  <artifactId>oop</artifactId>
  <version>0.9.9-SNAPSHOT</version>
</dependency>

For the oop project, I did do a 'mvn clean deploy', so the snapshot version should be somewhere in the maven central repository. But when I do a mvn clean install, the snapshot dependency above cannot be resolved and I get this:

Missing:

1) org.oop:oop:jar:0.9.9-SNAPSHOT

Try downloading the file manually from the project website.

Then, install it using the command:
mvn install:install-file -DgroupId=org.oop -DartifactId=oop -Dversion=0.9.9-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=org.oop -DartifactId=oop -Dversion=0.9.9-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

Is there a way to make maven download the snapshot automatically? I must be missing something here.

EDIT1: On my settings.xml I have:

   <server>
      <id>sonatype-nexus-snapshots</id>
      <username>XXXXXX</username>
      <password>XXXXXX</password>
    </server>

    <server>
      <id>sonatype-nexus-staging</id>
      <username>XXXXXX</username>
      <password>XXXXXX</password>
    </server>

EDIT2:
enter image description here

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

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

发布评论

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

评论(7

谜兔 2024-12-16 11:04:09

只需将其添加到您的 ~/.m2/settings.xml 中:

<profiles>
  <profile>
     <id>allow-snapshots</id>
        <activation><activeByDefault>true</activeByDefault></activation>
     <repositories>
       <repository>
         <id>snapshots-repo</id>
         <url>https://oss.sonatype.org/content/repositories/snapshots</url>
         <releases><enabled>false</enabled></releases>
         <snapshots><enabled>true</enabled></snapshots>
       </repository>
     </repositories>
   </profile>
</profiles>

Just add this to your ~/.m2/settings.xml:

<profiles>
  <profile>
     <id>allow-snapshots</id>
        <activation><activeByDefault>true</activeByDefault></activation>
     <repositories>
       <repository>
         <id>snapshots-repo</id>
         <url>https://oss.sonatype.org/content/repositories/snapshots</url>
         <releases><enabled>false</enabled></releases>
         <snapshots><enabled>true</enabled></snapshots>
       </repository>
     </repositories>
   </profile>
</profiles>
妄想挽回 2024-12-16 11:04:09

要更新快照,请尝试使用 -U 选项

-U,--update-snapshots                  Forces a check for updated
                                       releases and snapshots on remote
                                       repositories

但是,您说:

我确实执行了“mvn clean 部署”,因此快照版本应该位于 Maven 中央存储库中的某个位置。

这是不可能的,您的快照正在其他地方。如果我在没有配置我的个人存储库的情况下执行mvn clean deploy,我会得到:

部署失败:未在 POM 内的 distributionManagement 元素或 -DaltDeploymentRepository=id::layout::url 参数中指定存储库元素

要启用部署,需要在 pom.xml 中添加一些配置,例如:

<distributionManagement>

    <!-- Publish versioned releases here -->
    <repository>
        <id>myrepo</id>
        <name>My releases</name>
        <url>http://nexus.mycompany.com/nexus/content/repositories/releases</url>
    </repository>

    <!-- Publish snapshots here -->
    <snapshotRepository>
        <id>myrepo</id>
        <name>my snapshots</name>
        <url>http://nexus.mycompany.com/nexus/content/repositories/snapshots</url>
    </snapshotRepository>

</distributionManagement>

<repositories>
    <repository>
        <id>myrepo</id>
        <name>My Public Repository</name>
        <url>http://nexus.mycompany.com/nexus/content/groups/public</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

To update snapshots, try with the -U option

-U,--update-snapshots                  Forces a check for updated
                                       releases and snapshots on remote
                                       repositories

However, you said:

I did do a 'mvn clean deploy', so the snapshot version should be somewhere in the maven central repository.

This is just not possible, your snapshot is going somewhere else. If I do a mvn clean deploy without configuring my personal repository I get:

Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter

To enable deployment, there is some configuration to be added to pom.xml, like for instance:

<distributionManagement>

    <!-- Publish versioned releases here -->
    <repository>
        <id>myrepo</id>
        <name>My releases</name>
        <url>http://nexus.mycompany.com/nexus/content/repositories/releases</url>
    </repository>

    <!-- Publish snapshots here -->
    <snapshotRepository>
        <id>myrepo</id>
        <name>my snapshots</name>
        <url>http://nexus.mycompany.com/nexus/content/repositories/snapshots</url>
    </snapshotRepository>

</distributionManagement>

<repositories>
    <repository>
        <id>myrepo</id>
        <name>My Public Repository</name>
        <url>http://nexus.mycompany.com/nexus/content/groups/public</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
夏有森光若流苏 2024-12-16 11:04:09

Maven 会尝试自动下载快照,确实如此(如您的错误所示)。默认情况下,Maven 将每天查找一次较新的快照版本,但您可以在快照存储库配置中更改该间隔(例如在 settings.xml 中):

<updatePolicy>interval:5</updatePolicy>

这将使 Maven 每 5 分钟检查一次(如果您经常构建)。或者,您可以使用 -U--update-snapshots 选项来强制手动检查。

但是,它找不到依赖项。您可以发布快照依赖项的存储库设置和工件配置吗?

您的存储库中是否有 org.oop:oop:jar:0.9.9-SNAPSHOT 工件?

...所以快照版本应该位于 Maven 中央存储库中的某个位置。

不,不是。我试图查找它,但找不到。 Afaik,有一些暂存机制,所以也许您的设置是错误的。但通常情况下,正如其他人已经说过的,您会使用自己的存储库管理器,例如 Artifactory 或 Nexus。

Maven would try to download the snapshot automatically and indeed it does (as your error indicates). By default, Maven will look for newer snapshot versions once a day, but you can change that interval in your snapshot repository config (e.g. in settings.xml):

<updatePolicy>interval:5</updatePolicy>

This will make maven check every 5 minutes (if you build that often). Alternatively, you could use the -U or --update-snapshots option, to force the check manually.

However, it can't find the dependency. Could you post your repo settings and artifact config for the snapshot dependency?

Is the org.oop:oop:jar:0.9.9-SNAPSHOT artifact in your repository?

... so the snapshot version should be somewhere in the maven central repository.

No it isn't. I tried to look it up, but couldn't find it. Afaik, there's some staging mechanism, so maybe your settings are just wrong. But normally, as the others already said, you'd go and use your own repository manager like Artifactory or Nexus.

泪是无色的血 2024-12-16 11:04:09

您的存储库中是否存在该依赖项? (在 pom.xml 或 settings.xml 中)?

看起来不是。顺便说一句,看看你的配置,只是你没有使用 -o (离线)。您还可以使用 -U 刷新快照。

Does that dependency exists in your repository? (in pom.xml or settings.xml)?

Looks like not. By the way, take a look at your config, just you are not using -o (offline). Also you can use -U to refresh snapshots.

短叹 2024-12-16 11:04:09

您可以

  • 使用构建所有快照的父项目,或者
  • 使用例如 mvn:deploy 将快照部署到 Maven 构建服务器 (nexus/archiva/..)

You can either

  • use a parent project which builds all your snapshots, or
  • deploy your snapshots to your maven build server (nexus/archiva/..) using e.g., mvn:deploy
时光匆匆的小流年 2024-12-16 11:04:09

让我们稍微澄清一下术语,以确保不会产生误解。

“Maven Central”(http://search.maven.org/)是一个全球站点,您只能在其中找到发布。 Central 不接受快照,因此在那里部署应该会出现错误。

您可能指的是您的本地/公司范围的 Maven 代理/缓存。这些也可以配置为拒绝快照版本。对于 Nexus,您还可以定义更复杂的规则。就我而言,我遇到了一个问题,在mvn部署期间没有给出错误,但我可以在服务器日志中看到错误。

尝试跟踪数据:启用调试(mvn -X)以查看 Maven 将数据上传到哪里。然后检查服务器以查看工件是否真的上传。检查服务器日志是否有错误。

另请注意,快照依赖项每天仅刷新一次;所以这行不通:

PC #1: mvn install ->错误缺少依赖项
PC #2:mvn 部署
PC #1:mvn install ->由于“每天更新一次”策略,依赖关系仍然丢失

尝试 mvn install -U 强制 Maven 刷新其缓存的元数据。

Let's clear up terminology a bit to make sure there is no misunderstanding.

"Maven Central" (http://search.maven.org/) is a global site where you only find releases. Central doesn't accept snapshots so deploying there should give you an error.

You probably mean your local/company wide maven proxy/cache. These can also be configured to reject snapshot versions. In case of Nexus, you can also define more complex rules. In my case, I had an issue there which gave no error during mvn deploy but I could see an error in the server's logs.

Try to follow the data: Enable debug (mvn -X) to see where Maven uploads the data. Then check the server to see whether the artifacts were really uploaded. Check the server's logs for errors.

Also note that snapshot dependencies are only refreshed once a day; so this won't work:

PC #1: mvn install -> Error missing dependency
PC #2: mvn deploy
PC #1: mvn install -> Dependency is still missing because of "update once per day" policy

Try mvn install -U to force Maven to refresh its cached metadata.

和我恋爱吧 2024-12-16 11:04:09

即使在命令行上设置 -U,我也遇到了快照不更新的问题。对我来说,问题是我的客户端是 Maven 3,服务器是 Maven 2,并且在 Maven 3 中不再支持唯一快照。我们必须创建一个带有时间戳快照的新存储库来支持 3.xx 客户端。

I hit the issue of snapshots not updating even when setting -U on the command line. For me the issue was my client was Maven 3 and the server was Maven 2, and in Maven 3 unique snapshots are no longer supported. We had to create a new repository with timestamped snapshots to support the 3.xx clients.

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