简体   繁体   English

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

[英]Maven with Jenkins - Update parent pom version of dependency

I have a pom file that looks similar to this 我有一个类似于此的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>

If i run 'mvn release:prepare' on the above pom file, the version of the artifact changes. 如果我在上面的pom文件上运行'mvn release:prepare',则工件的版本会发生变化。 ie it becomes 即它成为

<version>1.2</version>

Now lets say i have gone and updated the portofino-war application which is a dependency of this pom file. 现在让我说我已经去了并更新了portofino-war应用程序,它是这个pom文件的依赖项。 portofino-war is now at version 3.1.11 but the parent pom file points to version 3.1.10 as shown above. portofino-war现在版本为3.1.11,但父pom文件指向版本3.1.10,如上所示。

Is there any way i can update the parent pom (either via Maven or Jenkins) file if a new version of portofino-war is built? 如果建立了新版本的portofino-war,我有什么方法可以更新父pom(通过Maven或Jenkins)文件?

Thanks 谢谢

Edit 编辑

The application uses Maven overlays - http://maven.apache.org/plugins/maven-war-plugin/overlays.html to build a war file from other war files. 该应用程序使用Maven覆盖 - http://maven.apache.org/plugins/maven-war-plugin/overlays.html从其他war文件构建war文件。 This means that if any of the dependent modules are built, the parent module has to be built to produce the final war file. 这意味着如果构建了任何依赖模块,则必须构建父模块以生成最终war文件。

The problem is that at the moment if i build any of the modules, i have to manually update the version in the parent pom file to build using the correct module version. 问题是,如果我构建任何模块,我必须手动更新父pom文件中的版本,以使用正确的模块版本进行构建。

Edit 2 编辑2

Thanks for your help Ralph. 谢谢你的帮助拉尔夫。 Basically this is what i would like to achieve: 基本上这就是我想要实现的目标:

What i am trying to do is create a maven project that will build a war file based on several modules. 我想要做的是创建一个maven项目,将基于几个模块构建一个war文件。 Assume the modules have the following structure: 假设模块具有以下结构:

Module 1 第1单元

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

Module2 单词数

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

Module3 单词数

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

Each of the modules shown will be developed by a different team. 所示的每个模块都将由不同的团队开发。 Each team produces a war file and installs it in the local maven repository. 每个团队生成一个war文件并将其安装在本地maven存储库中。 As an example the repository could look like this 作为示例,存储库可能如下所示

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 

Now the build manager uses the above war files to build the final deployable war file. 现在构建管理器使用上面的war文件来构建最终的可部署war文件。 I was originally planning to use maven overlays to merge the three war files. 我原计划使用maven叠加来合并三个war文件。 I did test the merging of war files with overlays and found that the following configuration worked. 我测试了使用叠加层合并war文件,发现以下配置有效。 ie using dependencies: 即使用依赖项:

Note: These dependencies are in the commonModule pom file 注意:这些依赖项位于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>

If i then build the commonModule module, i end up with one war file that contains all the contents of Module1, Module2 and Module3. 如果我然后构建commonModule模块,我最终得到一个war文件,其中包含Module1,Module2和Module3的所有内容。 Which ends up with something like this: 最终结果是这样的:

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   

The above works but requires a bit of manual intervention for a full release. 以上工作但需要一些人工干预才能完整发布。 Here is an example of what would happen if a module is modified 以下是修改模块时会发生什么的示例

Team 1 updating module 1 第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. 

The above does not use a multi module project as you suggested so i am trying to understand how the versioning would work with multi module projects. 上面没有像你建议的那样使用多模块项目,所以我试图理解版本控制如何与多模块项目一起工作。 For example, lets say the multi module project will look like this 例如,假设多模块项目看起来像这样

MyApp
 |- productModule
    |-pom.xml
 |- customerModule
    |-pom.xml
 |- commonModule
    |-pom.xml
 |-pom.xml
  • What is the difference in adding the version number in each child module compared to just havin the version number on the parent? 添加每个子模块中的版本号与仅使用父版本号相比有什么区别?
  • You say that the child modules will use the parent version. 您说子模块将使用父版本。 Lets say the parent version is currently version 3.4, how will it know that it is supposed to use version 3.1 of the productModule.war? 可以说父版本目前是版本3.4,它怎么会知道它应该使用productModule.war的3.1版本?
  • And finally, if team 1 has made a change to one of the child modules, would they still need to build it and deploy it on to the maven repository as an individual product first before building the multi-module project or can this be done as one step? 最后,如果团队1对其中一个子模块进行了更改,他们是否仍需要构建它并在构建多模块项目之前将其作为单个产品部署到maven存储库,或者可以将其作为一步?
  • How would this work if i want to make a patch release that does not necessarily mean using the latest version of a specific module? 如果我想制作补丁版本并不一定意味着使用特定模块的最新版本,这将如何工作?

Thanks 谢谢

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM