需要文件校验和

此规则检查指定文件是否具有给定的校验和。对于文本文件,请改用Require Text Files Checksum

此规则支持以下参数:

  • message - 如果规则失败,则向用户发送可选消息。如果未设置,将使用默认消息。
  • nonexistentFileMessage - 如果文件丢失,则向用户发送可选消息。如果未设置,将使用默认消息。
  • file - 要检查的文件。
  • 校验和 - 预期的文件校验和。
  • type - 计算校验和的散列算法类型。可能是“md5”、“sha1”、“sha256”、“sha384”或“sha512”之一。

示例插件配置:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>enforce-checksum</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireFileChecksum>
                  <file>E:\java-workspace\apache-maven-enforcer\maven-enforcer\target\checkout\enforcer-rules\target\classes/foo.txt</file>
                  <checksum>d41d8cd98f00b204e9800998ecf8427e</checksum>
                  <type>md5</type>
                </requireFileChecksum>
                <requireFileChecksum>
                  <file>E:\java-workspace\apache-maven-enforcer\maven-enforcer\target\checkout\enforcer-rules\target\classes/bar.txt</file>
                  <checksum>da39a3ee5e6b4b0d3255bfef95601890afd80709</checksum>
                  <type>sha1</type>
                </requireFileChecksum>
                <requireFileChecksum>
                  <file>E:\java-workspace\apache-maven-enforcer\maven-enforcer\target\checkout\enforcer-rules\target\classes/baz.txt</file>
                  <checksum>e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855</checksum>
                  <type>sha256</type>
                </requireFileChecksum>
                <requireFileChecksum>
                  <file>E:\java-workspace\apache-maven-enforcer\maven-enforcer\target\checkout\enforcer-rules\target\classes/qux.txt</file>
                  <checksum>38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b</checksum>
                  <type>sha384</type>
                </requireFileChecksum>
                <requireFileChecksum>
                  <file>E:\java-workspace\apache-maven-enforcer\maven-enforcer\target\checkout\enforcer-rules\target\classes/quux.txt</file>
                  <checksum>cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e</checksum>
                  <type>sha512</type>
                </requireFileChecksum>
              </rules>
              <fail>true</fail>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>