gpt4 book ai didi

java - Maven with Jenkins - 更新依赖的父 pom 版本

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:52:49 28 4
gpt4 key购买 nike

我有一个类似于此的 pom 文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myApp</groupId>
<artifactId>myAppId</artifactId>
<packaging>war</packaging>
<version>1.2-SNAPSHOT</version>
<name>Maven Test Webapp</name>
<url>http://maven.apache.org</url>

<dependency>
<groupId>com.manydesigns</groupId>
<artifactId>portofino-war</artifactId>
<version>3.1.10</version>
<type>war</type>
<scope>compile</scope>
</dependency>

</dependencies>
<build>
<finalName>TestName</finalName>
</build>
</project>

如果我在上面的 pom 文件上运行“mvn release:prepare”, Artifact 的版本就会改变。即它变成了

<version>1.2</version>

现在假设我已经更新了 portofino-war 应用程序,它是这个 pom 文件的依赖项。 portofino-war 现在是 3.1.11 版,但父 pom 文件指向 3.1.10 版,如上所示。

如果构建了新版本的 portofino-war,我有什么方法可以更新父 pom(通过 Maven 或 Jenkins)文件?

谢谢

编辑

应用程序使用 Maven 覆盖 - http://maven.apache.org/plugins/maven-war-plugin/overlays.html从其他 war 文件构建 war 文件。这意味着如果构建了任何依赖模块,则必须构建父模块以生成最终的 war 文件。

问题是目前如果我构建任何模块,我必须手动更新父 pom 文件中的版本以使用正确的模块版本构建。

编辑2

感谢拉尔夫的帮助。基本上这就是我想要实现的目标:

我想做的是创建一个 Maven 项目,该项目将基于多个模块构建一个 war 文件。假设模块具有以下结构:

模块 1

customerModule
|-webapp
|-jsp
|-customer
|-findCustomer.jsp
|-addNewCustomer.jsp
|-deleteCustomer.jsp
|-src
|-com
|-mycompany
|-customer
|-FindCustomerAction.java
|-AddCustomerAction.java
|-DeleteCustomer.java

模块二

productModule
|-webapp
|-jsp
|-product
|-productCustomer.jsp
|-addNewProduct.jsp
|-deleteProduct.jsp
|-src
|-com
|-mycompany
|-product
|-FindProductAction.java
|-AddProductAction.java
|-DeleteProduct.java

模块 3

commonModule
|-webapp
|-css
|-style.css
|-jsp
|-templates
|-coreTemplate.jsp
|-src
com
|-mycomany
|-common
|-Logger.java
|-Access.java
|-META-INF
|-MANIFEST.MF
|-context.xml
|-WEB-INF
|-lib
|-oraclejdbc.lib
|-log4j.lib
|-common.lib
|-struts-config.xml
|-tiles-def.xml
|-web.xml

显示的每个模块都将由不同的团队开发。每个团队生成一个 war 文件并将其安装在本地 maven 存储库中。例如,存储库可能如下所示

com
|-customerModule
|-customerModule.v2.1.war
|-customerModule.v3.0.war
|-productModule
|-productModule.v3.0.war
|-productModule.v3.1.war
|-commonModule
|-commonModule.v0.5.war
|-commonModule.v3.0.war

现在构建管理器使用上述 war 文件来构建最终可部署的 war 文件。本来打算用maven overlays来合并三个war文件。我确实测试了 war 文件与覆盖的合并,发现以下配置有效。即使用依赖项:

注意:这些依赖在commonModule pom文件中

<dependency>
<groupId>com</groupId>
<artifactId>customerModule</artifactId>
<version>3.0</version>
<type>war</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com</groupId>
<artifactId>productModule</artifactId>
<version>3.1</version>
<type>war</type>
<scope>compile</scope>
</dependency>

如果我随后构建 commonModule 模块,我最终会得到一个 war 文件,其中包含 Module1、Module2 和 Module3 的所有内容。结果是这样的:

MyApp.war
|-webapp
|-css
|-style.css
|-jsp
|-customer
|-findCustomer.jsp
|-addNewCustomer.jsp
|-deleteCustomer.jsp
|-product
|-productCustomer.jsp
|-addNewProduct.jsp
|-deleteProduct.jsp
|-templates
|-coreTemplate.jsp
|-META-INF
|-MANIFEST.MF
|-context.xml
|-WEB-INF
|-lib
|-oraclejdbc.lib
|-log4j.lib
|-common.lib
|-customerModule.jar
|-productModule.jar
|-classes
|-com
|-mycomany
|-common
|-Logger.class
|-Access.class
|-struts-config.xml
|-tiles-def.xml
|-web.xml

以上内容有效,但需要一些手动干预才能完整发布。这是一个模块被修改后会发生什么的例子

团队 1 更新模块 1

- Team 1 makes changes to module 1 and check in changes into CVS    
- Team 1 installs module 1 onto the maven repository by issuing mvn:prepare and mvn:perform on module 1. This adds a new version of customerModule.war on to the local repository
- Team 1 updates the dependency version for module 1 in the pom file used to merge the war files (i.e. commonModule)
- Team 1 builds the deployable war file by building the commonModule.

上面没有像您建议的那样使用多模块项目,所以我试图了解版本控制如何与多模块项目一起工作。例如,假设多模块项目看起来像这样

MyApp
|- productModule
|-pom.xml
|- customerModule
|-pom.xml
|- commonModule
|-pom.xml
|-pom.xml
  • 在每个子模块中添加版本号与在父模块中添加版本号相比有什么区别?
  • 您说子模块将使用父版本。假设父版本当前是 3.4 版,它如何知道它应该使用 productModule.war 的 3.1 版?
  • 最后,如果团队 1 对其中一个子模块进行了更改,在构建多模块项目之前,他们是否仍需要首先构建它并将其作为单独的产品部署到 Maven 存储库中,或者这可以吗?一步完成?
  • 如果我想制作一个不一定意味着使用特定模块的最新版本的补丁版本,这将如何工作?

谢谢

最佳答案

对于问题“编辑”部分中描述的场景,我建议将所有 war 文件放在一个:多模块项目中。

关于java - Maven with Jenkins - 更新依赖的父 pom 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9670158/

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