maven-replacer-plugin和多个文件 [英] maven-replacer-plugin and multiple files

查看:275
本文介绍了maven-replacer-plugin和多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个Java Web应用程序,在构建时我将URL替换为静态内容以添加版本信息,主要是为了进行缓存.

I wrote a Java Web Application where I replace URLs to static content at build time to add version information, primarely for caching.

例如,href="myapp/css/default.min.css"变成href="myapp-0.2.8/css/default.min.css"

我正在使用maven maven-replacer-plugin,并且对于一个文件来说一切正常:

I am using the maven maven-replacer-plugin and things work fine for one single file:

使用file-Tag替换单个文件.

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调试输出在工作示例中显示了这一点.

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.

不起作用的示例

根据使用指南,我应该能够将多个文件与includes:include

Not Working Example

According to the Usage Guide I should be able to use multiple files with includes:include

但是以下pom.xml配置没有任何作用(请注意,第15行的include-Tags开始)

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>

Debug输出如下.该文件存在.

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?

推荐答案

这似乎是最新的1.5.2版本中的错误.

This seems to be a bug in the latest 1.5.2 Version.

将错误修正级别的版本更改为1.5.1后,不起作用的示例将按预期工作,并且所有标记都将替换为其值.

As soon as I change the version on bugfix level down to 1.5.1, the Not Working Example works just as expected and all tokens are replaced by their values.

<plugin>
  <groupId>com.google.code.maven-replacer-plugin</groupId>
  <artifactId>replacer</artifactId>
  <version>1.5.1</version>
  <executions>
    <execution>
      <phase>prepare-package</phase>
      <goals>
        <goal>replace</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <includes>
      <include>${project.build.directory}/myApp/index.jsp</include>
    </includes>
    <replacements>
      <replacement>
        <token>%PROJECT_VERSION%</token>
        <value>${project.version}</value>
      </replacement>
    </replacements>
  </configuration>
</plugin>

我还按照ben的建议删除了ignoreMissingFile.

I also removed the ignoreMissingFile as suggested by ben.

这篇关于maven-replacer-plugin和多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆