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.
Use standard
META-INF\MANIFEST.MF
(Then you can use Java codegetClass().getPackage().getImplementationVersion()
to get version)For .war use this configuration:
That will add manifest during build, or you can call
mvn war:manifest
See also How to get package version at running Tomcat?
For a Spring Boot application, follow the accepted answer from above however substituting
with
Here's the link to the documentation https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.3-Release-Notes#maven-resources-filtering
One possibility is to store all project properties to the built
.jar
usingmaven-properties-plugin
.Then you can read these properties using standard (though not too practical) Java Properties API.
Be careful with this approach as it may leak properties that are not supposed to end up published, also from
settings.xml
.I just did this with an ant task.
What you are referring to is called filtering
You need to enable filtering on a particular resource, and then use
${project.version}
which will be substituted as part of your buildTo add to Sean's answer, you can move the version file to a folder location within the jar by using the targetpath parameter within resource. The following code creates a folder called 'resources' within the jar and the text file (version.number) is found in that folder.