给定 src/main/resources/hello.xml 中的以下属性
<test>${resolved.property}</test>
<test>${unresolved.property}</test>
具有属性:
resolved.property=test
在通过 mvn:resources 过滤后,我如何验证是否还有任何未解析的属性?
最佳答案
您可以使用 XML Maven Plugin在资源过滤完成后验证您的 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>
此处很重要,因为您要确保在过滤资源后 运行验证。
关于maven - 检查 Maven 资源中未解析的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45628169/