6

我目前在尝试设置项目以部署到内部 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
4

3 回答 3

9
  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>
    
于 2012-09-13T19:28:52.143 回答
5

所以最好的线索实际上就在我眼前的日志中。我认为唯一由我正在使用的 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}. 此外,这个配置有点误导,应该通过attachClasses战争插件的属性来完成。

于 2010-11-06T02:51:39.537 回答
1

难道是因为神器版本没有-SNAPSHOT后缀?

于 2010-11-05T02:25:19.467 回答