Require File Size

This rule checks that the specified list of files exist and are within the specified size range.

The following parameters are supported by this rule:

  • message - an optional message to the user if the rule fails.
  • files - A list of files to check. If this list is empty, the main project artifact will be checked.
  • maxsize - maximum size in bytes for this file.
  • minsize - minimum size in bytes for this file.
  • recursive - the mode for computing the size when the files are directories. Default is false, so the size reflects the directory itself and not its contents. If set to true, the size is computed by summing up the sizes of all files under the designated directory recursively.
  • allowNulls - If null files should be allowed. If allowed, they will be treated as if they do exist. Default is false.
  • satisfyAny - Allows that one of files can make the rule pass, instead of all the files. Default is false.

Sample Plugin Configuration:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>3.6.0</version>
        <executions>
          <execution>
            <id>enforce-file-size</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireFilesSize>
                  <maxsize>10000</maxsize>
                  <minsize>90</minsize>
                  <files>
                   <file>${project.build.outputDirectory}/foo.txt</file>
                   <file>${project.build.outputDirectory}/foo2.txt</file>
                  </files>
                </requireFilesSize>
                <requireFilesSize>
                  <maxsize>500000</maxsize>
                  <recursive>true</recursive>
                  <files>
                      <file>${project.build.directory}</file>
                  </files>
                </requireFilesSize>
              </rules>
              <fail>true</fail>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>