Maven with Jenkins - update parent pom version of a dependency
I have a pom file that is similar to this
<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" in the above pom file, the version of the artifact changes. those. becomes
Now let's say that I went away and updated the portofino-war app, which is a dependency of that pom file. portofino-war is now at version 3.1.11, but the original pom file points to version 3.1.10 as shown above.
Is there any way to update the parent pom (or via Maven or Jenkins) file if a newer version of portofino-war is built?
The app uses Maven overlays - http://maven.apache.org/plugins/maven-war-plugin/overlays.html to generate a war file from other war files. This means that if any of the dependent modules are built, the parent module must be created to create the final war file.
The problem is that at the moment, if I am building any of the modules, I need to manually update the version in the parent pom to build with the correct version of the module.
Thanks for your help Ralph. This is basically 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 multiple modules. Let's assume the modules have the following structure:
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
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 command creates a war file and installs it into the local maven repository. As an example, the repository might 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
The build manager now uses the above war files to create the final war deployment file. It was originally planned to use maven overlays to combine three war files. I checked the merge of war files with overlays and found that the following configuration worked. that is, using dependencies:
Note. These dependencies are in the pOM commonModule file
<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 create a commonModule, I get a single war file containing all the contents of Module1, Module2 and 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 a little manual intervention is required for full release. Here is an example of what happens if the module is changed
Update module 1 command 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 version control would work with multi-module projects. For example, let's say a project with multiple modules would 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 versus just the version number for the parent?
- You are saying that child modules will use the parent version. Let's say the parent version is currently version 3.4, how does it know if it is supposed to use version 3.1 of the product Module.war?
- And finally, if Team 1 made a change to one of the child modules, would they still have to build it and deploy it to the maven repository as a separate product before building a multi-module project, or could this be done as one step?
- How would this work if I want to make a patch release that doesn't necessarily mean using the latest version of a particular module?
source to share
You can use dependency range instead of pom update: http://docs.codehaus.org/display/MAVEN/Dependency+Mediation+and+Conflict+Resolution#DependencyMediationandConflictResolution-DependencyVersionRanges
source to share