About Us
At 1C we develop not only a platform
Entry
We most often use maven as a build system for Java applications, and in this short article we would like to talk about one of the problems that we had to face in the process of organizing development, and about the approach that allowed us to overcome this problem.
Prerequisites and workflow
Due to the specifics of development in our maven projects, we use a lot of modules, dependencies and child projects. The number of pom files in one tree can be in the tens or even hundreds.
It would seem: nothing terrible, once created and forgotten. If you need to change or add something in all files at once, there are a lot of handy tools in editors and IDEs. And what is the most common regular pom.xml change? We believe that the change of project versions and dependencies. Perhaps someone will want to argue with this, but this is the case with us. The reason lies in the fact that along with the kernel we develop a lot of our own libraries in parallel, and for the constant reproducibility of build and test results, using snapshots does not seem to us a convenient approach. For this reason, you have to raise the version number in projects with each build.
Also, from time to time, a developer needs to build his own branch of a library and check its performance against all dependencies, for which they all have to manually change the version.
Initial decision
With such frequent and multiple version changes, the process within CI wants to be simplified and automated. This is where a handy well-known plugin comes to the rescue. versions-maven-plugin - connect it and run
mvn -N versions:set -DnewVersion=2.0.1
and maven will do everything as it should: run through the hierarchy from top to bottom, replace all versions - beauty! Now it remains to raise a pull-request, colleagues will review the changes, and you can quickly join the trunk. Quickly? No matter how. A couple of hundred pom.xml for review, and that's not counting the code. In addition, no one is immune from merge conflicts with such a large number of modified files. It should be noted here that in the CI process, version changes occur automatically along with a change in functionality, and not somehow separately.
New opportunities
For a while we calmed down and, having resigned ourselves, we lived like that until the guys from
mvn -Drevision=2.0.0 clean package
System property values ββtake precedence over values ββdefined inproperties>.
Parent
4.0.0
org.apache
apache
18
org.apache.maven.ci
ci parent
First CI Friendly
${revision}${sha1}${changelist}
...
1.3.1
-SNAPSHOT
A descendant
4.0.0
org.apache.maven.ci
ci parent
${revision}${sha1}${changelist}
org.apache.maven.ci
ci child
...
If you want to build version 2.0.0-SNAPSHOT, then just use
mvn -Drevision=2.0.0 clean package
If you want to make a release, then just reset SNAPSHOT
mvn -Dchangelist= clean package
*The examples above are taken from
The harsh reality
Everything is good and great, it's time to experience a sense of satisfaction, but no. It turns out that this method will not work for install and deploy, since it will not be replaced in the descriptions of artifacts published in the repository ${revision} on its value and maven will not understand what it is all about.
org.apache
apache
${revision}
A light in the end of a tunnel
We must look for a solution to the problem. The situation could be saved
Adding a plugin to a project
org.codehaus.mojo
flatten-maven-plugin
1.1.0
true
resolveCiFriendliesOnly
flattens
process resources
flattens
flatten.clean
clean
clean
Done!
Happy ending
From now on, in order to change the version of the entire project and let all dependencies know about it, we just need to edit the elementRevision>only one root pom.xml. Not a hundred or two of these files with the same change arrive at the review, but one. Well, there is no need to use versions-maven-plugin.
Source: habr.com