I want to generate an zip file that will update an application with maven. The zip will be hosted on a server and I am using the assembly plugin to generate the zip. However I would like maven to automatically generate a text file that stores the current version number outside the zip. Is this possible?
EDIT: I successfully did it using the maven Assembly Plugin and two descriptor to create two custom assemblies. One has a directory-single goal and it just creates a folder with the updated version.txt based on filtering. Then another one with a single goal actually packages the zip file. This seems to be very inelegant and I guess it will not properly up date the maven repo with the whole updated folder. If there is a better way to do this please let me know.
in Maven 3, Use Sean's answer to create your
version.txt
file, (mine is shown here, along with build date and active profile):adding property
profileID
to each of the profiles, e.g.:Use Maven copy-resources to copy the file to an easier to reach directory such as
${basedir}
or${basedir}/target
:output looks like this:
I prefer the write-properties-file-maven-plugin, because I don't want all maven-project-properties in one file:
Sure. Create a text file somewhere in src/main/resources, call it
version.txt
(or whatever)File content:
now in your pom.xml, inside the build element, put this block:
after every build, the file (which you can find in target/classes) will contain the current version.
Now if you want to move the file somewhere else automatically, you are probably going to need to execute an ant task via the maven-antrun-plugin.
Something like this:
You could also use a Groovy script to produce a version info file. I like this method more because you don't have to exclude stuff in the assembly-plugin's descriptor. You can also use this method to optionally include stuff only available if you are building from Jenkins/Hudson (e.g. check oug BUILD_ID etc...).
So you would have a file-generating groovy script in pom.xml like this:
And then your assembly plugin plugin in pom.xml that would look like this:
And finally your assembly descriptor dist-all.xml would look like this: