为什么 Maven(错误地?)将我的 SNAPSHOT 部署到发布存储库和快照存储库?

发布于 2024-09-30 19:42:37 字数 3895 浏览 7 评论 0原文

我目前在尝试设置项目以部署到内部 Nexus 存储库时遇到问题。由于我对 Maven 总体来说还很陌生,所以我希望在如何设置分发管理方面有一些我不太理解的地方。

基本问题是,当我执行“mvn deploy”时,工件已成功部署到快照存储库,但 Maven 也尝试将其部署到发布存储库,但失败了......正如它应该的那样。我对当前配置的理解是,它也不应该将其部署到发布存储库。

我已经在下面包含了各种配置元素,但我想知道我是否真的应该使用配置文件来管理该部分,以便仅定义快照构建,并且仅定义发布构建。

对此的任何帮助/澄清将非常感激。

我的 POM 中有以下内容用于分发管理:

<distributionManagement>
<repository>
  <id>internal-releases</id>
  <name>Internal Releases</name>
  <url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
  <id>internal-snapshots</id>
  <name>Internal Snapshots</name>
  <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

在 POM 的其他位置,我进行了以下设置以允许使用这些存储库来获取工件:

<repositories>
<repository>
  <id>internal-releases</id>
  <url>http://localhost:8081/nexus/content/repositories/releases</url>
  <snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
  <id>internal-snapshots</id>
  <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
  <snapshots><enabled>true</enabled></snapshots>
</repository>
<!-- other repos, etc, etc -->
</repositories>

我在 settings.xml 中有正确的设置,以提供能够发布到的凭据这个测试 Nexus 实例在我的计算机上运行,​​实际上它正在成功部署快照。

问题是它还尝试将快照部署到发布存储库,该存储库配置为禁止快照。

“mvn deploy”的输出包括以下内容:

[INFO] [deploy:deploy {execution: default-deploy}]
[INFO] Retrieving previous build number from internal-snapshots
Uploading: http://localhost:8081/nexus/content/repositories/snapshots/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-8.war
405K uploaded  (service-1.0.0-20101104.170338-8.war)
[INFO] Retrieving previous metadata from internal-snapshots
[INFO] Uploading repository metadata for: 'snapshot com.internal:service:1.0.0-SNAPSHOT'
[INFO] Retrieving previous metadata from internal-snapshots
[INFO] Uploading repository metadata for: 'artifact com.internal:service'
[INFO] Uploading project information for service 1.0.0-20101104.170338-8
[INFO] [deploy:deploy-file {execution: default}]
[INFO] Retrieving previous build number from remote-repository
[INFO] repository metadata for: 'snapshot com.internal:service:1.0.0-SNAPSHOT' could not be found on repository: remote-repository, so will be created
Uploading: http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error deploying artifact: Failed to transfer file: http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar. Return code is: 400

来自 Nexus 的日志包含以下内容(正如我所期望的那样):

jvm 1    | 2010-11-04 13:03:39 INFO  [p-759477796-118] - o.s.n.p.m.m.M2Repos~          - Storing of item releases:/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar is forbidden by Maven Repository policy. Because releases is a RELEASE repository
jvm 1    | 2010-11-04 13:03:39 ERROR [p-759477796-118] - o.s.n.r.ContentPlex~          - Got exception during processing request "PUT http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar": Storing of item releases:/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar is forbidden by Maven Repository policy. Because releases is a RELEASE repository

I'm currently experiencing a problem while trying to set up a project to deploy to an internal nexus repository. Since I'm rather new to Maven in general, I expect that there is just something that I'm not really comprehending in how to set up distribution management.

The basic issue is that when I execute "mvn deploy" the artifact is being successfully deployed to the snapshot repository, but Maven is also attempting to deploy it to the release repository, which is failing ... as it should. My understanding of my current configuration is that it should NOT be deploying it to the release repository as well.

I've included the various configuration elements below, but I'm wondering if I actually am supposed to be managing the section with a profile so that snapshot builds only have defined, and release builds have only defined.

Any help/clarification on this would be incredibly appreciated.

I have the following in my POM for distribution management:

<distributionManagement>
<repository>
  <id>internal-releases</id>
  <name>Internal Releases</name>
  <url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
  <id>internal-snapshots</id>
  <name>Internal Snapshots</name>
  <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

Elsewhere in the POM I have the following set up to allow use of these repositories to obtain artifacts:

<repositories>
<repository>
  <id>internal-releases</id>
  <url>http://localhost:8081/nexus/content/repositories/releases</url>
  <snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
  <id>internal-snapshots</id>
  <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
  <snapshots><enabled>true</enabled></snapshots>
</repository>
<!-- other repos, etc, etc -->
</repositories>

I have the correct settings in my settings.xml to provide credentials to be able to publish to this test nexus instance running on my computer, and it is in fact successfully deploying the snapshot.

The problem is that it also tries to deploy the snapshot to the release repository, which is configured to disallow snapshots.

The output from "mvn deploy" includes the following:

[INFO] [deploy:deploy {execution: default-deploy}]
[INFO] Retrieving previous build number from internal-snapshots
Uploading: http://localhost:8081/nexus/content/repositories/snapshots/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-8.war
405K uploaded  (service-1.0.0-20101104.170338-8.war)
[INFO] Retrieving previous metadata from internal-snapshots
[INFO] Uploading repository metadata for: 'snapshot com.internal:service:1.0.0-SNAPSHOT'
[INFO] Retrieving previous metadata from internal-snapshots
[INFO] Uploading repository metadata for: 'artifact com.internal:service'
[INFO] Uploading project information for service 1.0.0-20101104.170338-8
[INFO] [deploy:deploy-file {execution: default}]
[INFO] Retrieving previous build number from remote-repository
[INFO] repository metadata for: 'snapshot com.internal:service:1.0.0-SNAPSHOT' could not be found on repository: remote-repository, so will be created
Uploading: http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error deploying artifact: Failed to transfer file: http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar. Return code is: 400

The log from Nexus contains the following (as I would expect it to):

jvm 1    | 2010-11-04 13:03:39 INFO  [p-759477796-118] - o.s.n.p.m.m.M2Repos~          - Storing of item releases:/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar is forbidden by Maven Repository policy. Because releases is a RELEASE repository
jvm 1    | 2010-11-04 13:03:39 ERROR [p-759477796-118] - o.s.n.r.ContentPlex~          - Got exception during processing request "PUT http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar": Storing of item releases:/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar is forbidden by Maven Repository policy. Because releases is a RELEASE repository

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

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

发布评论

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

评论(3

寂寞笑我太脆弱 2024-10-07 19:42:37
  1. 在 pom 中定义以下属性

    ${project.distributionManagement.snapshotRepository.url};
    
  2. 按如下方式更改 maven-deploy-plugin 的配置:

    <前><代码><插件>;
    org.apache.maven.plugins
    maven-deploy-plugin;
    <版本>2.5
    <配置>
    <跳过>真

    <处决>
    <执行>
    <阶段>部署
    <配置>
    <包装>罐子
    true
    ${deployFileUrl}
    ${project.artifactId};
    ${project.groupId};
    <版本>${project.version}
    <文件>${project.build.directory}/${project.build.finalName}.jar

    <目标>
    <目标>部署文件



  3. 添加以下配置文件以使用存储库 url 设置deployFileUrl 属性

    <前><代码><配置文件>;
    <简介>
    释放模式
    <属性>
    ${project.distributionManagement.repository.url}


  4. 最后在 maven-release-plugin 中调用此配置文件

    <前><代码><插件>;
    org.apache.maven.plugins
    maven-release-plugin;
    <版本>2.0-beta-9
    <配置>
    发布模式

  1. Define following property in your pom

    <deployFileUrl>${project.distributionManagement.snapshotRepository.url}</deployFileUrl>
    
  2. Change configuration of maven-deploy-plugin as follows:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.5</version>
        <configuration>
            <skip>true</skip>
        </configuration>
        <executions>
            <execution>
                <phase>deploy</phase>
                <configuration>
                    <packaging>jar</packaging>
                    <generatePom>true</generatePom>
                    <url>${deployFileUrl}</url>
                    <artifactId>${project.artifactId}</artifactId>
                    <groupId>${project.groupId}</groupId>
                    <version>${project.version}</version>
                    <file>${project.build.directory}/${project.build.finalName}.jar</file>
                </configuration>
                <goals>
                    <goal>deploy-file</goal>
                </goals>
            </execution>
         </executions>
     </plugin>
    
  3. Add following profile to set the deployFileUrl property with repository url

    <profiles>
        <profile>
            <id>release-mode</id>
            <properties>
                <deployFileUrl>${project.distributionManagement.repository.url}</deployFileUrl>
            </properties>
        </profile>
    </profiles>
    
  4. Finally call this profile in maven-release-plugin

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.0-beta-9</version>
        <configuration>
            <releaseProfiles>release-mode</releaseProfiles>
        </configuration>
     </plugin>
    
失而复得 2024-10-07 19:42:37

所以最好的线索实际上就在我眼前的日志中。我认为由我正在使用的 POM 生成的唯一工件是 .war,但您会在日志中注意到 Maven 尝试部署到发行版的工件实际上是 .jar。

这足以作为一个指针(Maven 用户邮件列表中的某个人提供的指针)来查找并最终发现有人为部署阶段包含了以下额外配置。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
  <phase>deploy</phase>
    <goals>
      <goal>deploy-file</goal>
    </goals>
    <configuration>
      <packaging>jar</packaging>
      <generatePom>true</generatePom>
      <url>${project.distributionManagement.repository.url}</url>
      <artifactId>${project.artifactId}</artifactId>
      <groupId>${project.groupId}</groupId>
      <version>${project.version}</version>
      <file>${project.build.directory}/${project.build.finalName}.jar</file>
    </configuration>
  </execution>
</executions>
</plugin>

请注意,这实际上是直接引用 ${project.distributionManagement.repository.url}。此外,此配置有些误导,实际上应该通过 war 插件的attachClasses 属性来完成。

So the best clue actually turned out to be right in front of my eyes in the log. The only artifact I had thought was being produced by the POM I was working with was a .war, but you'll notice in the log that the artifact which Maven is attempting to deploy to the release is actually a .jar.

This was enough of a pointer (that someone on the Maven users mailing list pointed provided) to look for and eventually find that someone had included the following extra configuration for the deploy phase.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
  <phase>deploy</phase>
    <goals>
      <goal>deploy-file</goal>
    </goals>
    <configuration>
      <packaging>jar</packaging>
      <generatePom>true</generatePom>
      <url>${project.distributionManagement.repository.url}</url>
      <artifactId>${project.artifactId}</artifactId>
      <groupId>${project.groupId}</groupId>
      <version>${project.version}</version>
      <file>${project.build.directory}/${project.build.finalName}.jar</file>
    </configuration>
  </execution>
</executions>
</plugin>

Notice that this is in fact directly referencing ${project.distributionManagement.repository.url}. Also, this configuration was somewhat misguided and should really have been accomplished via the attachClasses property of the war plugin.

送你一个梦 2024-10-07 19:42:37

难道是因为工件版本没有-SNAPSHOT后缀?

Could it be because the artifact version does not have -SNAPSHOT suffix?

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