How to put maven project version in war file manifest?

24,015

Solution 1

Figured it out using the maven-war-plugin. See the configuration below:

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-war-plugin</artifactId>
     <version>2.1.1</version>
     <configuration>
         <archive>
             <manifestEntries>
                 <version>${project.version}</version>
             </manifestEntries>
         </archive>
     </configuration>
</plugin>

Solution 2

Or you can use the addDefaultImplementationEntries or addDefaultSpecificationEntries flags which will add several entries including the project.version property.

addDefaultImplementationEntries

Implementation-Title: ${project.name}
Implementation-Version: ${project.version}
Implementation-Vendor-Id: ${project.groupId}
Implementation-Vendor: ${project.organization.name}
Implementation-URL: ${project.url}

addDefaultSpecificationEntries

Specification-Title: ${project.name}
Specification-Version: ${project.version}
Specification-Vendor: ${project.organization.name}

Default value for both is false. If a property is not defined (e.g. project.organization.name), then that line will be excluded from the manifest.

This could go into the maven-war-plugin configuration as follows:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <archive>
            <manifest>
                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            </manifest>
        </archive>
    </configuration>
</plugin>
Share:
24,015
Matthew Kubicina
Author by

Matthew Kubicina

I'm a technology leader based in New York, NY. Currently, I am heading up engineering at BaubleBar, an eCommerce start-up in Manhattan.

Updated on January 08, 2020

Comments

  • Matthew Kubicina
    Matthew Kubicina over 4 years

    I need to have Maven insert the version number from the POM file into the manifest located in the WAR file under /WEB-INF/manifest.mf.

    How do I do this? I was able to easily file documentation for doing this in a JAR file using the maven-jar-plugin, but that does not work on a WAR file.

    Thanks for the help!