Andrey Shylnikov
Andrey Shylnikov

Reputation: 41

Maven overwrites file with replaced string

I'm creating web-app with Java+Spring+FreeMarker, and, I want to write app version directly into FreeMarker template. I try using maven replacer plugin, but, when I create war package, file with replaced string (in target directory) becomes overriden with file with origin token. Here is quote from pom.xml:

<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
 <execution>
  <phase>generate-resources</phase>
  <goals>
   <goal>replace</goal>
  </goals>
 </execution>
</executions>
<configuration>
 <includes>
  <include>${basedir}\src\main\webapp\templates\include\version.ftl
  </include>
 </includes>
 <outputFile>${basedir}\target\${project.build.finalName}\templates\include\version.ftl
 </outputFile>
<replacements>
 <replacement>
  <token>version</token>
  <value>${project.build.finalName}</value>
 </replacement>
</replacements>
</configuration>
</plugin>

What I'm doing wrong?

Upvotes: 0

Views: 268

Answers (1)

Andrey Shylnikov
Andrey Shylnikov

Reputation: 41

I've found solution. Need to use prepare-package phase in war plugin:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<useCache>true</useCache>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
<version>2.6</version>
<executions>
<execution>
<id>prepare-war</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>

Upvotes: 0

Related Questions