I wrote a Java Web Application where I replace URLs to static content at build time to add version information, primarely for caching.
For example, href="myapp/css/default.min.css"
is turned into href="myapp-0.2.8/css/default.min.css"
I am using the maven maven-replacer-plugin and things work fine for one single file:
Working Example
Using the file-Tag for single file replacements.
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<ignoreMissingFile>false</ignoreMissingFile>
<file>${project.build.directory}/myApp/index.jsp</file>
<replacements>
<replacement>
<token>%PROJECT_VERSION%</token>
<value>${project.version}</value>
</replacement>
</replacements>
</configuration>
</plugin>
Maven Debug Output shows this for the working example.
[DEBUG] Configuring mojo 'com.google.code.maven-replacer-plugin:replacer:1.5.2:replace' with basic configurator -->
[DEBUG] (s) basedir = .
[DEBUG] (s) commentsEnabled = true
[DEBUG] (s) encoding = UTF-8
[DEBUG] (s) file = /Users/phisch/Development/MyApp/Workspace/MyApp-WebApp/target/myApp/index.jsp
[DEBUG] (s) ignoreErrors = false
[DEBUG] (s) ignoreMissingFile = false
[DEBUG] (s) preserveDir = true
[DEBUG] (s) quiet = false
[DEBUG] (s) token = %PROJECT_VERSION%
[DEBUG] (s) value = 0.3
[DEBUG] (s) replacements = [com.google.code.maven_replacer_plugin.Replacement@3bccdcbd]
[DEBUG] (s) skip = false
[DEBUG] (s) unescape = false
[DEBUG] -- end configuration --
[DEBUG] Replacement run on /Users/phisch/Development/MyApp/Workspace/MyApp-WebApp/target/myApp/index.jsp and writing to /Users/phisch/Development/MyApp/Workspace/MyApp-WebApp/target/myApp/index.jsp with encoding UTF-8
[INFO] Replacement run on 1 file.
Not Working Example
According to the Usage Guide I should be able to use multiple files with includes:include
But the following pom.xml configurations does nothing (Note the include-Tags startin at line 15)
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<ignoreMissingFile>false</ignoreMissingFile>
<includes>
<include>${project.build.directory}/myApp/index.jsp</include>
</includes>
<replacements>
<replacement>
<token>%PROJECT_VERSION%</token>
<value>${project.version}</value>
</replacement>
</replacements>
</configuration>
</plugin>
The Debug output is as follows. The file exists.
DEBUG] Configuring mojo 'com.google.code.maven-replacer-plugin:replacer:1.5.2:replace' with basic configurator -->
[DEBUG] (s) basedir = .
[DEBUG] (s) commentsEnabled = true
[DEBUG] (s) encoding = UTF-8
[DEBUG] (s) ignoreErrors = false
[DEBUG] (s) ignoreMissingFile = false
[DEBUG] (s) includes = [/Users/phisch/Development/MyApp/Workspace/MyApp-WebApp/target/myApp/index.jsp]
[DEBUG] (s) preserveDir = true
[DEBUG] (s) quiet = false
[DEBUG] (s) token = %PROJECT_VERSION%
[DEBUG] (s) value = 0.3
[DEBUG] (s) token = %MyApp_PROJECT_VERSION%
[DEBUG] (s) value = 0.3 (Build: 20130301-1130)
[DEBUG] (s) replacements = [com.google.code.maven_replacer_plugin.Replacement@235d4338, com.google.code.maven_replacer_plugin.Replacement@3fe823ab]
[DEBUG] (s) skip = false
[DEBUG] (s) unescape = false
[DEBUG] -- end configuration --
[INFO] Replacement run on 0 file.
How can I replace the same token/value pairs in multiple files?