Maven插件:如何用文件中的时区替换当前日期?

时间:2020-05-14 16:10:57

标签: maven maven-plugin maven-antrun-plugin build-helper-maven-plugin

我使用maven-antrun-plugin

<properties>
    <build.date>${maven.build.timestamp}</build.date>
    <maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
</properties>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
       <execution>
         <id>copy-gherkin-formatter-file</id>
         <phase>verify</phase>
         <goals>
            <goal>run</goal>
         </goals>
         <configuration>
         <target name="copy">

          <copy
                file="src/test/resources/dev/index.html"
                tofile="target/reports/html/index.html"
                overwrite="true" />  
                <replace file="target/reports/html/index.html">
                    <replacefilter>
                       <replacetoken>@build-date@</replacetoken>
                       <replacevalue>${build.date}</replacevalue>
                    </replacefilter>
                </replace>
            </target>
        </configuration>
    </execution>
</plugin>

但是我的日期是UTC。我需要设置时区。所以我尝试使用build-helper-maven-plugin

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
      <execution>
        <id>timestamp-property</id>
        <goals>
          <goal>timestamp-property</goal>
        </goals>
        <configuration>
            <name>build.time</name>
            <pattern>MM/dd/yyyy hh:mm aa</pattern>
            <locale>en_US</locale>
            <timeZone>America/Detroit</timeZone>
          </configuration>
      </execution>
    </executions>
  </plugin>

然后将<replacevalue>${build.date}</replacevalue>更改为<replacevalue>${build.time}</replacevalue>,但我的结果是${build.time}(变量不会随值更改)。

0 个答案:

没有答案
相关问题