views:

95

answers:

1

I wonder, if it is possible to get currently used version of maven for filtering resource file.

I've a resource file, that is filtered by maven:

version=${project.version}
buildDate=${timestampFormatted}
buildBy=${user.name}
name=${project.artifactId}
buildVersion=${build.number}
osName=${os.name}
osArch=${os.arch}
osVersion=${os.version}
fileEncoding=${file.encoding}

and now I would prefer to save currently used maven version, too.

Is there any thing like ${maven.version}?

Thanks a lot.

+4  A: 

The build-helper-maven-plugin can do this. Check out the build-helper:maven-version goal, it sets a property containing the current version of maven (maven.version by default).

For example, the following pom sets the property and then uses the property to save the maven version to the project jar's manifest.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.3</version>
        <executions>
          <execution>
            <id>maven-version</id>
            <goals>
              <goal>maven-version</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <archive>
            <manifestEntries>
              <Maven-Version>${maven.version}</Maven-Version>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>
Pascal Thivent
+1 must always remember the build-helper plugin
Rich Seller