How to put maven project version in war file manifest?

蹲街弑〆低调 提交于 2019-12-02 20:25:11

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>

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>

Put ${project.version} in your manifest.mf where you want the version to be. In order for this to work, I believe you need the resources plugin so that manven will 'filter' resources as they are included in your war file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!