gpt4 book ai didi

java - Maven 从两个单独的 pom.xml 部署两个具有不同分类器的 jar

转载 作者:搜寻专家 更新时间:2023-11-01 03:34:05 24 4
gpt4 key购买 nike

我想部署两个具有不同分类器的 jar Artifact ,但目前失败了,因为它们都提供了各自版本的 pom.xml。我该如何解决这个问题,以便两个 pom.xml 都可以与其 Artifact 一起上传?

示例 - 我有 com.test.company.somelib-1.0.0-cmp1.jarcom.test.company.somelib-1.0.0-cmp2.jar,其中 cmpX 是分类器。这两个包包含(逻辑上)相同的代码和类(相同版本),它们仅在预处理方式上略有不同。分类器注释存在是因为我们需要维护向后兼容性。

长话短说,第一个 Artifact 上传正常,第二个上传失败并返回 Forbidden,因为我们的存储库不允许覆盖 Artifact (我想保持这种状态)。

创建这两个包的管道略有不同,因此更容易将它们的构建分开。我只想将它们部署为两个具有相同名称和不同分类器的包。

感谢帮助


编辑:建议使用 Maven 配置文件。我可以看到他们会工作,但他们不会是理想的。

考虑我在下图中描述的设置 - 有一个 CI 服务器 (TeamCity)。

  • 有一个“入门”版本(来源)。此构建检查所有必需的源文件。
  • 从这个入门构建中触发了几个其他构建(使用 x.x.x 处理/编译)。这些中的每一个构建调整一个template-pom.xml(填充特定的classifier和其他信息),然后构建并将其 Artifact 部署到我们的Artifactory。

enter image description here

如果我决定添加另一个processing-build,我想要实现的设置,我需要做的就是添加另一个“分支”。如果我使用的是配置文件,我还需要向 pom.xml 文件添加一个新的配置文件。

如有错误请指正。配置文件似乎能够实现目标,但不是很理想,至少在我看来是这样。

最佳答案

我强烈反对让 2 个(或更多)不同的 pom 文件具有相同的 GAV。

但我知道您的需求是由遗留原因引起的。我自己没有尝试过,但它可能有效:保留一个构建(= maven 项目),因为你现在拥有它。在另一个构建中跳过正常部署并手动调用部署插件的部署文件目标,如下所示:

<build>
<plugins>
<!-- skip normal execution of deploy plugin -->
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>

<!-- invoke with goal: deploy-file -->
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>someId</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<inherited>false</inherited>
<configuration>
<file>path-to-your-artifact-jar</file>
<generatePom>false</generatePom>
<artifactId>xxx</artifactId>
<groupId>xxx</groupId>
<version>xxx</version>
<classifier>xxx</classifier>
<packaging>xxx</packaging>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

关于java - Maven 从两个单独的 pom.xml 部署两个具有不同分类器的 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37114624/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com