【问题标题】:Why is Maven (incorrectly?) deploying my SNAPSHOT to both the release and snapshot repositories?为什么 Maven(不正确?)将我的 SNAPSHOT 部署到发布和快照存储库?
【发布时间】:2011-05-05 04:56:49
【问题描述】:

我目前在尝试设置项目以部署到内部 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 中有正确的设置,以提供能够发布到我的计算机上运行的这个测试关系实例的凭据,实际上它正在成功部署快照。

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

“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

【问题讨论】:

    标签: maven maven-deploy-plugin


    【解决方案1】:
    1. 在你的 pom 中定义以下属性

      <deployFileUrl>${project.distributionManagement.snapshotRepository.url}</deployFileUrl>
      
    2. 修改maven-deploy-plugin的配置如下:

      <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. 添加以下配置文件以使用存储库 url 设置 deployFileUrl 属性

      <profiles>
          <profile>
              <id>release-mode</id>
              <properties>
                  <deployFileUrl>${project.distributionManagement.repository.url}</deployFileUrl>
              </properties>
          </profile>
      </profiles>
      
    4. 最后在 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>
      

    【讨论】:

      【解决方案2】:

      所以最好的线索实际上就在我眼前的日志中。我认为唯一由我正在使用的 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属性来完成。

      【讨论】:

        【解决方案3】:

        会不会是神器版本没有-SNAPSHOT后缀?

        【讨论】:

        • 神器版本是1.0.0-SNAPSHOT,所以没有。
        • 我认为这个答案应该是评论
        猜你喜欢
        • 2020-12-08
        • 2012-06-08
        • 2011-11-12
        • 2019-09-28
        • 1970-01-01
        • 1970-01-01
        • 2011-09-02
        • 1970-01-01
        • 2015-12-05
        相关资源
        最近更新 更多