mvn部署:将快照和发布版本文件存储到不同的存储库

发布于 2024-11-27 02:21:08 字数 1139 浏览 2 评论 0原文

是否可以以某种方式告诉 Maven 部署:文件目标根据项目的版本是否是快照/发布来部署到两个独立的工件?

我希望可能有一个属性表明该版本已预先添加 -SNAPSHOT,或者可能是要部署到的默认工件(已根据版本号确定)。

我考虑过使用两个不同的配置文件,并通过解析 pom.xml 文件来确定它是否是 ant 中的快照,但如果可能的话,我宁愿采用更干净的解决方案。

目前,我的部署插件如下所示,但这只是部署到发布工件,无论版本如何;

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-deploy-plugin</artifactId>
   <version>2.5</version>
   <executions>
      <execution>
        <id>deploy-zip-created-by-ant-to-artifactory</id>
    <phase>deploy</phase>
    <goals>
       <goal>deploy-file</goal>
    </goals>
    <configuration>
       <repositoryId>${project.distributionManagement.repository.id}</repositoryId>
       <url>${project.distributionManagement.repository.url}</url>
       <file>${project.basedir}/Build/deploy/MyArtifact.zip</file>
       <pomFile>${project.basedir}/MyArtifact-pom.xml</pomFile>
    </configuration>
      </execution>
   </executions>
</plugin>

非常感谢

Is it possible to in some way tell the maven deploy:file goal to deploy to two independent artifactories based on whether the version of the project is a snapshot / release?

I'm hoping there might be a property which indicates the fact the version has -SNAPSHOT prepended, or perhaps the default artifactory to deploy to (which has been worked out based on the version number already).

I thought about using two different profiles and working out if its a snapshot in ant by parsing the pom.xml file, but I'd rather a cleaner solution if possible.

Currently, my deploy plugin looks as follows, but this just deploys to the release artifactory regardless of the version;

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-deploy-plugin</artifactId>
   <version>2.5</version>
   <executions>
      <execution>
        <id>deploy-zip-created-by-ant-to-artifactory</id>
    <phase>deploy</phase>
    <goals>
       <goal>deploy-file</goal>
    </goals>
    <configuration>
       <repositoryId>${project.distributionManagement.repository.id}</repositoryId>
       <url>${project.distributionManagement.repository.url}</url>
       <file>${project.basedir}/Build/deploy/MyArtifact.zip</file>
       <pomFile>${project.basedir}/MyArtifact-pom.xml</pomFile>
    </configuration>
      </execution>
   </executions>
</plugin>

Many Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

吐个泡泡 2024-12-04 02:21:08

如果您在 settings.xml 中定义了存储库,则可以使用

mvn deploy:deploy-file -DrepositoryId=releases -DartifactId=... -Durl=

If you defined your repositories within your settings.xml you can use the

mvn deploy:deploy-file -DrepositoryId=releases -DartifactId=... -Durl=
微暖i 2024-12-04 02:21:08

这里,我使用 GMaven 插件从 POM 的 distributionManagement 部分选择存储库并将其存储在属性中。

然后部署插件可以使用该属性。

Over here, I used the GMaven plugin to choose the repository from the distributionManagement section of the POM and store it in a property.

The deploy plugin can then use that property.

爱要勇敢去追 2024-12-04 02:21:08

也许您想使用 build-helper-maven-plugin 进行部署额外的工件

Maybe you want to use the build-helper-maven-plugin to deploy an additional artifact

雄赳赳气昂昂 2024-12-04 02:21:08

这可能是 Maven 方式:

  <distributionManagement>
    <repository>
      <id>release</id>
      <url>http://my-releases</url>
    </repository>
    <snapshotRepository>
      <id>snapshots</id>
      <url>http://my-snapshots</url>
    </snapshotRepository>
  </distributionManagement>

在部署快照版本时,它将进入快照存储库。对于非快照版本,将使用常规存储库。

只需运行部署即可。 :-)

This is presumably the Maven way:

  <distributionManagement>
    <repository>
      <id>release</id>
      <url>http://my-releases</url>
    </repository>
    <snapshotRepository>
      <id>snapshots</id>
      <url>http://my-snapshots</url>
    </snapshotRepository>
  </distributionManagement>

When doing a deploy of a snapshot version, it'll go the snapshots repository. For a non-snapshot release the regular repository will be used.

Just run deploy and it'll work. :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文