How-to add the Maven version number to the MANIFEST.MF file?

For the Apache MyFaces Trinidad project I wanted to include the Maven version number, into the MANIFEST.MF

The solution itself is pretty straightforward. You can use an existing plugin, to get the version number. The inclusion to the MANIFEST.MF is done with one of the packaging plugins (e.g. maven-jar-plugin).

Add the following to your pom.xml file, to integrate the build-helper-maven-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>
...

Now you can include the version information in to the generated MANIFEST.MF file. For that, just add the $maven.version variable to the manifestEntries section of your maven-jar-plugin:

...
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <archive>
      <manifestEntries>
        <Maven-Version>${maven.version}</Maven-Version>
        ...
      </manifestEntries>
    </archive>
...

That’s all you need!

About these ads

Howdy!

Posted in Uncategorized
One comment on “How-to add the Maven version number to the MANIFEST.MF file?
  1. [...] This post was mentioned on Twitter by Brett Porter and Matthias Wessendorf, olamy. olamy said: RT @mwessendorf: How-to add the Maven version number to the MANIFEST.MF file? http://goo.gl/GQqEq [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 33 other followers

%d bloggers like this: