首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么Maven错误地将快照上传到发布存储库?

为什么Maven错误地将快照上传到发布存储库?
EN

Stack Overflow用户
提问于 2012-06-05 00:29:09
回答 2查看 12K关注 0票数 2

我正在尝试使用maven-deploy-plugin将版本和快照上传到Nexus存储库。然而,我遇到了这个错误

代码语言:javascript
复制
[INFO] [deploy:deploy {execution: default-deploy}]
[INFO] Retrieving previous build number from nexus
Uploading: http://localhost:8081/nexus/content/repositories/snapshots/info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120605.140242-20.jar
56K uploaded  (edr-app-1.0.4-20120605.140242-20.jar)
[INFO] Uploading project information for edr-app 1.0.4-20120605.140242-20
[INFO] Retrieving previous metadata from nexus
[INFO] Uploading repository metadata for: 'artifact info.afilias.edr:edr-app'
[INFO] Retrieving previous metadata from nexus
[INFO] Uploading repository metadata for: 'snapshot info.afilias.edr:edr-app:1.0.4-SNAPSHOT'
[INFO] Retrieving previous build number from nexus
Uploading: http://localhost:8081/nexus/content/repositories/snapshots/info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120605.140242-20.tar.gz
4286K uploaded  (edr-app-1.0.4-20120605.140242-20.tar.gz)
[INFO] [deploy:deploy-file {execution: default}]
Uploading: http://localhost:8081/nexus/content/repositories/releases/info/afilias/edr/edr-app/1.0.4/edr-app-1.0.4.tar.gz
89530K uploaded  (edr-app-1.0.4.tar.gz)
[INFO] Uploading project information for edr-app 1.0.4
[INFO] Retrieving previous metadata from remote-repository
[INFO] Uploading repository metadata for: 'artifact info.afilias.edr:edr-app'
[INFO] Retrieving previous build number from remote-repository
[INFO] repository metadata for: 'snapshot info.afilias.edr:edr-app:1.0.4-SNAPSHOT' could not be found on repository: remote-repository, so will be created
Uploading: http://localhost:8081/nexus/content/repositories/releases/info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120605.140242-20.tar.gz
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error deploying attached artifact /home/mren/trunk2/target/edr-app-1.0.4-SNAPSHOT.tar.gz: Error deploying artifact: Failed to transfer file: http://localhost:8081/nexus/content/repositories/releases/info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120605.140242-20.tar.gz. Return code is: 400

下面是我在pom.xml中的配置:

代码语言:javascript
复制
<project>
 ...
    <distributionManagement>
       <repository>
          <id>releases</id>
          <name>Releases</name>
          <url>http://localhost:8081/nexus/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
          <id>snapshots</id>
          <name>Snapshots</name>
          <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
      </distributionManagement>
  ...
  <build>
   ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <phase>deploy</phase>
            <goals>
              <goal>deploy-file</goal>
            </goals>
            <configuration>
              <file>target/edr-install-1.0.4-${revision}.tar.gz</file>
              <url>${project.distributionManagement.repository.url}</url>
              <packaging>tar.gz</packaging>
              <artifactId>artifactId</artifactId>
              <groupId>groupId</groupId>
              <version>1.0.4-${revision}</version>
            </configuration>
          </execution>
        </executions>
      </plugin>
   ...
  </build>
...
</project>

从我的settings.xml文件中:

代码语言:javascript
复制
<settings>
  <server>
      <id>releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>
  <profiles>
    <profile>
      <id>nexus</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <id>releases</id>
          <name>Releases</name>
          <url>http://localhost:8081/nexus/content/repositories/releases</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
        <repository>
          <id>snapshots</id>
          <name>Snapshots</name>
          <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      </profile>
  </profiles>
</settings>

我确信这个配置曾经有效,但是现在它产生了一个错误。不确定出了什么问题。

并且节点日志告诉我,它正在尝试将快照上载到发布库中

代码语言:javascript
复制
jvm 1    | 2012-06-04 14:16:31 INFO  [tp1706427008-35] - org.sonatype.nexus.proxy.maven.maven2.M2Repository - Storing of item releases:/info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120604.181534-1.tar.gz is forbidden by Maven Repository policy. Because releases is a RELEASE repository
jvm 1    | 2012-06-04 14:16:31 ERROR [tp1706427008-35] - org.sonatype.nexus.rest.ContentPlexusResource - Got exception during processing request "PUT http://localhost:8081/nexus/content/repositories/releases/info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120604.181534-1.tar.gz": Storing of item releases:/info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120604.181534-1.tar.gz is forbidden by Maven Repository policy. Because releases is a RELEASE repository
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-06-05 03:17:26

您的settings.xml不正确。请将Maven配置为使用Nexus correctly following the book chapter.,特别是使用镜像设置和其中的url,而不是存储库和pluginRepository的特定url。

它会干扰您正确的Maven pom,并最终尝试将快照部署到发布库中,这是不正确的。

此外,使用正确的目标/命令也很重要。不要直接使用部署文件目标。

只需运行该命令

mvn clean deploy

在构建中。

还有另一个澄清。Maven将部署由版本决定的任何内容。如果它以-SNASPHOT结尾,则它是一个开发版本并被发布到快照存储库(并且将允许重新部署递增版本号),如果它不是,它被认为是一个发行版,并将被部署到发布存储库。一个项目不能同时是快照和发布。这是一个或另一个。

不要混淆发布和快照这两个概念!

在部署额外的工件方面,如果它们没有关联,我会将它们拉到一个单独的项目/模块中,或者如果它们是关联的,我会查看构建助手插件的附加工件目标。

票数 3
EN

Stack Overflow用户

发布于 2012-06-06 01:56:39

这是因为您正在告诉Maven部署一个看起来像快照的文件。看一下您的deploy:deploy-file配置。${revision}与快照具有相同的格式,因此Nexus对其执行nack:

目标/edr-.tar.gz-1.0.4-${revision}版本变为: info/afilias/edr/edr-app/1.0.4-SNAPSHOT/edr-app-1.0.4-20120605.140242-20.tar.gz

作为参考,Maven和Nexus用来决定快照是什么/不是什么的正则表达式在这里介绍:http://www.sonatype.com/people/2008/05/maven-code-how-to-detect-if-you-have-a-snapshot-version/

我推荐的另一件事是不要使用deploy:deploy- tar.gz,而是使用buildhelper:attach来附加这个文件,这样文件就会被恰当地命名,从而避免你对修订版本所做的所有修改。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10884714

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档