Christopher Klewes
Christopher Klewes

Reputation: 11445

Maven filter resources and adding project version

This is an easy filter approach to write the project version into a file.

<build>
 <resources>
  <resource>
    <directory>src/main/webapp</directory>
    <includes>
      <include>**/*.version</include>
    </includes>
    <filtering>true</filtering>
  </resource>
 </resources>
</build>

This is the project structure (left out the unintresting parts)

├───src
│   └───main
│       ├───java
│       │   └─── [...]
│       └───webapp
│           ├───META-INF
│           └───WEB-INF
│               ├───cfg
│               └───portal.version
└─── pom.xml

The content of portal.version

${project.version}

This should be replaced with the artifact version of the pom.xml, but unfortunately nothing happens. Whats wrong? Thank you in advance

Upvotes: 8

Views: 7004

Answers (3)

Joselo
Joselo

Reputation: 147

This is solved in this post and also there's an additional step, you have to include this under maven-resources-plugin:

<delimiters>
    <delimiter>${*}</delimiter>
</delimiters>

At least that worked for me and I had the exact same issue as you.

Upvotes: 1

Eugene Kuleshov
Eugene Kuleshov

Reputation: 31795

When you specify resource element, the result filtered content is copied into a target/classes folder. To filter web app resources you could configure maven-war-plugin.

Though to get the version, in most cases it is better to read a standard Maven property file in your application, e.g. META-INF\maven\<groupId>\<artifactId>\pom.properties

Upvotes: 4

brabster
brabster

Reputation: 43580

To filter web resources, you can use the filtering capabilities of the war plugin.

Upvotes: 1

Related Questions