【问题标题】:Deploying multiple files in single pom在单个 pom 中部署多个文件
【发布时间】:2016-11-07 11:42:28
【问题描述】:

我有一个 pom,它可以获取一些 zip,解压缩并部署其中的 5 个工件(jar + pom)。

它看起来像:

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <executions>
                    <execution>
                        <id>default-deploy</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>deploy-api-jar</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy-file</goal>
                        </goals>
                        <configuration>
                            <file>target/xxx.jar</file>
                            <pomFile>target/xxx/pom.xml</pomFile>
                            <sources>target/xxx-sources.jar</sources>
                            <repositoryId>${nexus-repository-id}</repositoryId>
                            <url>http://${nexus.deploy.server}/${nexus-repository-path}</url>
                        </configuration>
                    </execution>

所以我对 5 个不同的工件执行了 5 次。

它适用于第一个工件,但由于它尝试再次上传它而失败:

[INFO] Uploading: http://www.zzz.com:8081/nexus/content/repositories/mobile-r/xxx/server/deployall/8.1.17/deployall-8.1.17-dependencies.dot

由于depedencies.dot 8.1.17 已经部署,它会因400 BadRequest 而失败。

为什么它会尝试在每个工件之间上传depedencies.dot?我可以禁用它吗?

【问题讨论】:

标签: maven deployment maven-deploy-plugin


【解决方案1】:

编辑:答案错过了重点

它失败了,因为 Maven 和你的关系只允许一个工件用于给定的一组坐标。

所以,如果你想将它们全部部署到相同的坐标,你需要给它们不同的分类器。

您想要做的是高度不规则地使用构建脚本。 Maven 假设来自单个 POM 的所有工件都具有相同的坐标(但不同的分类器)。如果需要,您可以将工件附加到项目并在生命周期中使用普通的deploy:deploytask 上传它们。您可以为此使用build-helper-maven-plugin

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>1.12</version>
  <executions>
    <execution>
      <id>attach-artifacts</id>
      <phase>package</phase>
      <goals>
        <goal>attach-artifact</goal>
      </goals>
      <configuration>
        <artifacts>
          <artifact>
            <file>file1</file>
            <type>extension of your file</type>
            <classifier>x</classifier>
          </artifact>
          <artifact>
            <file>file2</file>
            <type>extension of your file</type>
            <classifier>y</classifier>
          </artifact>
          ...
          </artifacts>
        </configuration>
      </execution>
    </executions>
  </plugin>

但是由于您要上传 5 个分离的工件,因此 POM 不是您想要的,请改用 bash 脚本进行上传(多次调用 mvn deploy:deploy-file)。

【讨论】:

  • 坐标你的意思是 groupId:artifactId ?但它们不共享相同的坐标,它们是 5 个不同的工件。我通过调用具有相同功能的 bash 脚本来使其工作,部署文件。你不推荐这个解决方案?
  • 好的,我错过了对不同文件使用不同 POM 的部分。在这种情况下,bash 文件实际上是最干净的解决方案(我回答的最后一段)。您没有实际项目,因此只需上传它们。至于为什么会发生这种情况,JF Meier 对您的问题的评论指出了正确的解释。
猜你喜欢
  • 2021-09-05
  • 2010-10-12
  • 1970-01-01
  • 2017-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多