【问题标题】:How to deploy the sources file with the jar using deploy:deploy-file如何使用 jar 部署源文件 deploy:deploy-file
【发布时间】:2012-03-10 16:32:34
【问题描述】:

我有以下插件用于创建 -sources.jar 并将特定命名的 jar 部署到存储库。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <executions>
        <execution>
            <id>attach-sources</id>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <version>${project.version}-r${buildNumber}</version>
        <classifier>${env}</classifier>
        <packaging>jar</packaging>
        <file>${project.build.directory}/${project.build.finalName}.jar</file>
        <url>${artifactory.url}/libs-release-local</url>
        <repositoryId>artifactory.digiterre.com</repositoryId>
        <pomFile>${project.basedir}/pom.xml</pomFile>
    </configuration>
</plugin>

我希望同时部署*-sources.jar。我尝试添加第二个文件条目,甚至是第二个部署插件。我似乎部署了一个或其他文件。

是否可以使用deploy:deploy-file 一次性部署两者,或者我是否必须设置第二个团队城市构建来部署源?

【问题讨论】:

  • 我看过那个帖子并尝试了这些建议。两者都不起作用,因为我正在部署具有特定分类器的文件。 jar-no-fork 也不起作用 Maven 会引发错误。
  • 有点脏,但也许使用 Maven 的 Ant 任务从命令行执行部署?
  • 我没有使用任何 pom.xml 文件,来自 jenkin 我将如何动态传递版本号。建议我。

标签: java maven deployment jar maven-source-plugin


【解决方案1】:

我们可以使用deploy:deploy-file 在主 JAR 工件旁边上传多个 JAR(源代码、测试、文档)。我们只需要将那条附加信息提供给deploy:deploy-file 插件调用。添加的内容在以下命令中以粗体表示:

mvn deploy:deploy-file
-Dfile=helloWorld.jar
-Durl=https://localhost/nexus/content/repositories/snapshots/
-DrepositoryId=snapshot
-Dfiles=helloWorld-6.4.1.3.SNAPSHOT-sources.jar,helloWorld-6.4.1.3.SNAPSHOT-tests.jar
-Dtypes=jar ,jar -Dclassifiers=sources,tests
-DgroupId=com
-DartifactId=helloWorld
-Dversion=6.4.1.3.SNAPSHOT
-Dpackaging=jar
-Dpomfile=pom.xml

  • 我们需要指定用逗号分隔的文件列表。
  • 我们需要指定这些附加文件的类型。
  • 我们需要为这些附加文件添加分类信息。

【讨论】:

  • 请正确格式化答案。更多详情,请查看How to Answer
【解决方案2】:

当您使用maven-source-plugin 时,生成的jar 将自动附加到项目工件(this 参数的默认设置为'true'),如果您执行deploy,它将与它一起部署。唉,不需要单独配置部署插件。

不幸的是,您无法将分类器(在您的情况下为 ${env})添加到源 jar。这就是我使用以下配置的原因:

...
<artifactId>com.pie.mash.repo.mince-${env}</artifactId>
<version>1.18-r${buildNumber}</version>
...
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-source-plugin</artifactId>
      <version>2.1.2</version>
      <executions>
        <execution>
          <goals>
            <goal>jar-no-fork</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

另外,我在 SO 上找到了this 问题。您可以使用那里建议的解决方法。

【讨论】:

  • 明确使用 2.1.2 版本不会抛出我之前遇到的错误。
  • 但是,使用此示例仍未部署源。
  • @Yoztastic 你应该调用mvn clean deploy。而且,正如我已经提到的,不需要单独配置部署插件。
  • 完全删除 maven-deploy-plugin 无法解决对 maven-deploy-plugin v2.4 的依赖关系。保留现有的但删除配置部分会导致上传 jar 和源 jar 但缺少 r* 和 $env 部分。这很奇怪,因为在目标中使用正确的名称创建了正确的文件。
  • @Yoztastic 能否提供mvn deploy的日志文件?
【解决方案3】:

mvn deploy:deploy-file 仅部署单个工件。相反,您可以使用 mvn deploy(它调用 mvn deploy:deploy)来部署工件、它的 pom 以及附加的工件(如源代码和 javadoc)。参考maven deploy plugin的目标概述。

【讨论】:

  • 我正在使用 deploy:deploy-file url=repo.xxx.xxx.com/content/repositories/peroo-snapshots repositoryId=peroo-snapshots groupId=com.xxx.ist.curo.testtalentClient artifactId=pet_client_osx version=${CLIENT_VERSIONCITEST}.0-SNAPSHOT包装=tar 分类器=Rev_${SVN_REVISION} 文件=$WORKSPACE/CWave3/TalentOSX/build/Release/Talent.app.tar
  • CLIENT_VERSIONCITEST 环境变量每次都应该改变,但它不适用于 jenkins。
猜你喜欢
  • 2011-11-21
  • 1970-01-01
  • 2011-11-16
  • 1970-01-01
  • 2021-12-09
  • 2015-10-15
  • 1970-01-01
  • 2021-11-19
  • 2015-11-29
相关资源
最近更新 更多