我想把构建信息写入一个属性文件中。我找到了Maven资源过滤插件,以下是相关部分的pom文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>project.mygroup</groupId>
<artifactId>prject</artifactId>
<version>1.0-20190130-1</version>
</parent>
<artifactId>project-war</artifactId>
<packaging>war</packaging>
<version>1.0-20190130-1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>
yyy-MM-dd HH:mm
</maven.build.timestamp.format>
</properties>
<dependencies>
...
</dependencies>
<build>
<finalName>project</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<!-- Create war from the project -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
如果开始执行
mvn clean package
,构建将成功,但我的build.properties
文件在src/main/resources下不包含构建信息。我的属性文件如下:
build.version=${pom.version}
build.date=${timestamp}
build.url=${pom.url}
build.name=${pom.name}
我做错了什么?谢谢!