简体   繁体   中英

Copy Maven pom.xml with version change

Sorry for the long post, but I first have to explain our setup:

Setup

We produce some core jars that are used in multiple other projects that are actually released. Right now, many of our projects use Ant with Ivy. In fact, all of the core projects were strictly Ant with Ivy.

  • In our ivy.xml files, the version number is a property. This property is set universally because the developers didn't update this property when we went to a new release. This keeps all of our projects (including core jars) on the same version number.
  • We release our jars as Maven jars. We do this via the Ivy <ivy:makepom> task. When this task is used, the version number is automatically substituted for the property.
  • We also embed this pom.xml into our jars like Maven does.
  • We also create a second POM called pom-snapshot.xml . This is the same as the pom.xml , but it has -SNAPSHOT after the version number.

When Jenkins does a build, it automatically deploys the jar to our Snapshot repository. It uses mvn deploy:deploy-file and the pom-snapshot.xml file. This allows developers to try the jar before it's officially released.

When the developer is satisfied with the jar, they can promote that jar to our Maven Release repository. This uses the Jenkins promote plugin, the pom.xml , and mvn deploy:deploy-file .

What We Want

We now have a few core jar projects that are moving over to Maven. The developers want to keep this same system in place: Each build does a SNAPSHOT deployment to our Maven repo, and then the developer can deploy a selected build to our Maven repo via a Jenkins plugin.

Right now:

  • I copy the pom.xml under the target directory and use mvn deploy:deploy-file to deploy the jar into our Release repo. This is done by the developer using the Promote plugin in Jenkins and not with each build.
  • I also copy the pom.xml to a pom-snapshot.xml file under target. I use target. I use mvn deploy:deploy-file` to deploy this to the Snapshot repo after each build.

This works, but I use regular expressions to find the version number of the pom.xml , and if I have a pom.xml where the Super Pom version (the parent POM) is the same as the version in the pom.xml , I end up changing the wrong version.

I was wondering if there's a Maven Plugin that allows you to copy the pom.xml to another directory while changing the version number in the pom itself. Or, is there just a better way to handle this whole issue? I could setup Artifactory to not check version consistency between what I am deploying and the pom.xml , but that ended up giving us problems with OSGI projects and with developers not keeping up with the version number.

There is always maven-exec-plugin with which you can do almost anything. But I don't think it is a good idea. Since Maven is always about convention, you should better think of moving to maven-convenient process. With SNAPSHOT versions during development phase and release-prepare/perform to transform SNAPSHOT version into release one. Check maven-release-plugin here It can perform version updates, VCS updates and many more.

I found the maven-version-plugin to get what I need. I copy the pom.xml to a new directory, run versions:set on that pom.xml , and then move pom.xml to pom-snapshot.xml and pom.xml.versionsBackup to pom.xml .

All of this is inside our parent project pom.xml which sets the current version number, Java defaults, site defaults, etc., so the individual projects' pom.xml files are still clean and simple. Everything happens in the background.

I am not happy with the setup, but its compatible with the rest of our projects and their processes, and developers don't have to worry about any of it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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