首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么是Maven (错误的?)将我的快照同时部署到发行版和快照存储库?

为什么是Maven (错误的?)将我的快照同时部署到发行版和快照存储库?
EN

Stack Overflow用户
提问于 2010-11-05 01:28:20
回答 3查看 16.4K关注 0票数 6

我目前在尝试设置一个项目以部署到内部nexus库时遇到了一个问题。由于我对Maven总体上比较陌生,所以我希望在如何设置发行版管理方面有一些我并不真正理解的东西。

基本问题是,当我执行"mvn deploy“时,工件被成功地部署到快照存储库,但Maven也尝试将其部署到发布存储库,这是失败的……这是应该的。我对我当前配置的理解是,它不应该也将其部署到发布存储库。

任何关于这方面的帮助/澄清都将令人难以置信地感激。

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

代码语言:javascript
复制
<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的其他地方,我进行了以下设置,以允许使用这些存储库来获取工件:

代码语言:javascript
复制
<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“的输出包括:

代码语言:javascript
复制
[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的日志包含以下内容(正如我所期望的那样):

代码语言:javascript
复制
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
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-11-06 10:51:40

所以最好的线索实际上就在我眼前的日志里。我之前认为的惟一工件是一个.war,但是在日志中您会注意到,Maven正试图部署到发行版中的工件实际上是一个.jar。

代码语言:javascript
复制
<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属性来完成。

票数 5
EN

Stack Overflow用户

发布于 2012-09-14 03:28:52

  1. 在您的pom中定义以下属性

maven- ${project.distributionManagement.snapshotRepository.url}

  • Change -plugin的部署配置如下:

org.apache.maven.plugins maven- deploy -plugin 2.5真部署jar真${deployFileUrl} ${project.artifactId} ${project.groupId} ${project.version}${project.build.directory}/${project.build.finalName}.jar deploy-

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

发布模式${project.distributionManagement.repository.url} 插件最终在maven-release-

  • 中调用此配置文件

org.apache.maven.plugins maven-release-plugin 2.0-beta-9 release-mode

票数 9
EN

Stack Overflow用户

发布于 2010-11-05 10:25:19

会不会是因为工件版本没有-SNAPSHOT后缀?

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

https://stackoverflow.com/questions/4099412

复制
相关文章

相似问题

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