Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Java MANIFEST.MF to include Maven Version Number

I have the following in my project's pom.xml which I think should display the version of Maven being used in the resulting WAR file:

<build>
...
    <plugins>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>false</addClasspath>
                    </manifest>
                    <manifestEntries>
                        <Build-Time>${maven.build.timestamp}</Build-Time>
                        <Build-Host>${agent.name}</Build-Host>
                        <Build-User>${user.name}</Build-User>
                        <Build-Maven>Maven ${maven.version}</Build-Maven>
                        <Build-Java>${java.version}</Build-Java>
                        <Build-OS>${os.name}</Build-OS>
                        <Build-Label>${project.version}</Build-Label>
                        <Build-Path>${basedir}</Build-Path>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
        ...
    </plugins>
...
</build>

The MANIFEST.MF that is created looks correct see below apart from the Build-Maven line in which the ${maven.version} is not substituted with the actual version number 3.0.4 in this case.

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: stocjon
Build-Jdk: 1.6.0_35
Build-Host: 
Build-Java: 1.6.0_35
Build-Label: 1.0.0-SNAPSHOT
Build-Maven: Maven ${maven.version}
Build-OS: Windows XP
Build-Path: C:\Development\project_name
Build-Time: 15:38:50 21-Sep-2012
Build-User: user_name

Any ideas why Maven version is not being populated in the MANIFEST.MF ?

Help would be much appreciated.

Thanks Jon

like image 967
jcstock74 Avatar asked Sep 21 '12 15:09

jcstock74


People also ask

How do I find my Java Maven version?

Before moving on, we can check the default JDK version of Maven. Running the mvn -v command will show the Java version in which Maven runs.

Where is manifest file Maven?

By default, Maven Archiver creates the manifest file for you. It is sometimes useful to use your own hand crafted manifest file. Say that you want to use the manifest file src/main/resources/META-INF/MANIFEST.

What is Maven Archiver?

The Maven Archiver is mainly used by plugins to handle packaging. The version numbers referenced in the Since column on this page are the version of the Maven Archiver component - not for any specific plugin. To see which version of Maven Archiver a plugin uses, go to the site for that plugin.


2 Answers

You need to add this plugin:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
  <executions>
    <execution>
      <phase>validate</phase>
      <goals>
        <goal>maven-version</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Check here for details.

like image 163
Paulius Matulionis Avatar answered Oct 29 '22 22:10

Paulius Matulionis


We no more need the build-helper-maven-plugin since the feature (MSHARED-38) was added to the component maven-archiver : 2.5 in Feb. 2012 (release notes).

And this component is used by the Maven plugins like maven-jar-plugin, maven-war-plugin, maven-ear-plugin, etc.

The versions of these plugins using this feature are :

  • maven-jar-plugin : 2.4 (MJAR-148), released in Feb. 2012
  • maven-war-plugin : 2.2 (MWAR-273), released in Feb. 2012
  • maven-ear-plugin : 2.8 (MEAR-145), released in Sept. 2012
  • maven-assembly-plugin : 2.4 (MASSEMBLY-634), released in Nov. 2012
  • maven-ejb-plugin : 2.4 (MEJB-56), EDIT : released on 24/Aug/14
  • etc.

So now we'll have this entry by default in the archive's manifest.mf :

Created-By: Apache Maven ${maven.version}

like image 36
Guillaume Husta Avatar answered Oct 29 '22 23:10

Guillaume Husta