maven replacer插件无法正常工作

时间:2015-06-03 00:32:06

标签: maven maven-replacer-plugin

以下是pom.xml

的相关部分
 <plugin>
           <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
             <version>1.5.2</version>
            <executions>
              <execution>
             <phase>pre-package</phase>
                 <goals>
                    <goal>replace</goal>
                  </goals>
                 </execution>
                </executions>
                    <configuration>
                       <file>target/swagger/api.json</file>
                <regex>false</regex>
                <token>$BUILD_NUMBER$</token>
                <value>${project.version}</value>
                        </configuration>
 </plugin>

这是api.json档案

{
    "apiVersion": "$BUILD_NUMBER$"
    "developers": ["foo", "bar"]
} 

运行mvn clean package后,我看不到target/swagger/api.json更新了project.version

2 个答案:

答案 0 :(得分:1)

确保您的插件声明位于<build><plugins>

而不是<build><pluginManagement><plugins>

此外,如果您的项目是更大的maven项目的一部分,使用$ {project.build.directory}而不是target更安全:

<file>target/swagger/api.json</file>

答案 1 :(得分:0)

  1. 在想要替换它时考虑maven构建阶段,在使用swagger f.ex生成文档之前选择一个阶段。 “验证”并将swagger docs生成设置为“compile”
    1. 将$ BUILD_NUMBER $兑换为%BUILD_NUMBER%
    2. 考虑一下,您需要再次手动将值重置为%BUILD_NUMBER%