检查 Maven 资源中未解析的属性



给定src/main/resources/hello中的以下属性.xml

<test>${resolved.property}</test>
<test>${unresolved.property}</test>

具有属性:

resolved.property=test

在进行 mvn:resources 筛选后,如何验证是否还剩下任何未解析的属性?

您可以在资源过滤完成后使用 XML Maven 插件来验证您的 XML 文件。

此插件可以根据架构验证 XML 文件,甚至只是检查它们的格式是否正确(这足以验证您的 XML 文件不包含属性令牌(。

你像这样声明插件:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
<configuration>
<validationSets>
<validationSet>
<dir>... your xml dir ...</dir>
<includes>
<include>*.xml</include>
</includes>
</validationSet>
</validationSets>
</configuration>
</plugin>

注意:<phase>process-resources</phase>的使用在这里很重要,因为您希望确保在筛选资源运行验证。

最新更新