The Maven Verifier Plugin – Maven验证器插件

最后修改: 2018年 4月 19日

中文/混合/英文(键盘快捷键:t)

1. Overview

1.概述

This tutorial introduces the verifier plugin, one of the core plugins of the Maven build tool.

本教程介绍了verifier插件,这是Maven构建工具的核心插件之一。

For an overview of the other core plugins, refer to this overview article.

关于其他核心插件的概述,请参阅这篇概述文章

2. Plugin Goal

2.插件目标

The verifier plugin has only one goal – verify. This goal verifies the existence or non-existence of files and directories, optionally checking file content against a regular expression.

verifier插件只有一个目标 – verify这个目标是验证文件和目录的存在与否,可以选择根据正则表达式检查文件内容。

Despite its name, the verify goal is bound to the integration-test phase by default rather than the verify phase.

尽管它的名字是verify,但verify目标默认与integration-test阶段绑定,而不是verify阶段。

3. Configuration

3.配置

The verifier plugin is triggered only if it’s explicitly added to the pom.xml:

只有当verifier插件被明确添加到pom.xml时才会被触发。

<plugin>
    <artifactId>maven-verifier-plugin</artifactId>
    <version>1.1</version>
    <configuration>
        <verificationFile>input-resources/verifications.xml</verificationFile>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>

This link shows the newest version of the plugin.

此链接显示了该插件的最新版本。

The default location of the verification file is src/test/verifier/verifications.xml. We must set a value for the verificationFile parameter if we want to use another file.

验证文件的默认位置是src/test/verifier/verifications.xml。如果我们想使用其他文件,我们必须为verificationFile参数设置一个值。

Here’s the content of the verification file shown in the given configuration:

下面是给定配置中显示的验证文件的内容。

<verifications 
  xmlns="http://maven.apache.org/verifications/1.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/verifications/1.0.0 
  http://maven.apache.org/xsd/verifications-1.0.0.xsd">
    <files>
        <file>
            <location>input-resources/baeldung.txt</location>
            <contains>Welcome</contains>
        </file>
    </files>
</verifications>

This verification file confirms that a file named input-resources/baeldung.txt exists and that it contains the word Welcome. We’ve already added such a file before, thus the goal execution succeeds.

这个验证文件确认了一个名为input-resources/baeldung.txt的文件存在,并且它包含Welcome这个词。我们之前已经添加了这样一个文件,因此目标执行成功了。

4. Conclusion

4.结论

In this article, we walk through the verifier plugin and described how to customize it.

在这篇文章中,我们浏览了verifier插件,并描述了如何定制它。

The complete source code for this tutorial can be found over on GitHub.

本教程的完整源代码可以在GitHub上找到over

Next »

The Maven Site Plugin

« Previous

The Maven Clean Plugin