I am developing a project which uses versioning:
-
version name is typed in POM file
-
It is also used as a part of
to-be-created .msifile name :file_[version].msi -
It is used in a service name, after this project is installed from
.msi
Those params are kept in locations as follows:a)
.propertiesfile as aSpring param: version=0340b)in pom.xml
<package-version>0340</package-version>c)as a
<filename><version>.wxsfile, used bybuild.xmld) also in the abovementioned
.wxsfile as aMsiProductVersion = "3.4.0"(notice the dots)
Is there a way to define a parameter in some other config file, that would populate those files with proper data, as to keep the version in one place only. Now it is easy to overlook one param, and build a 340.msi which will display 330 Service as its name. I find it difficult since not all files belong to one model (like Spring).
You can configure Maven to replace “variables” in resources. Add this to your POM:
Now you can use
${project.version}and it will be replaced with the version from the POM in all files belowsrc/main/resourcesandsrc/test/resources.As for the other files, you can either use an embedded Ant task in your POM or write a small script (Ant, bash, whatever you like) that reads the POM and creates the other three files from templates.
Another option is to write a unit tests which reads all files and makes sure that they contains the correct values. That way, the version won’t be updated automatically but a) the version doesn’t change that often (which probably causes your problem) and b) the tests are much more powerful than what you can do in a script (they can, for example, read&update binary files).