Question

I would like to ensure the file size of resulting zip file is not larger than 400 MB so I've created this rule:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <executions>
          <execution>
            <id>enforce-file-size</id>
            <goals>
              <goal>enforce-once</goal>
            </goals>
            <configuration>
              <rules>
                <requireFilesSize>
                  <maxsize>419430400</maxsize> <!-- the final zip should not exceed 400 MB -->
                  <files>
                   <file>${project.build.outputDirectory}.zip</file>
                  </files>
                </requireFilesSize>
              </rules>
              <fail>true</fail>
            </configuration>
          </execution>
        </executions>
      </plugin>

However, the mvn enforcer is by default bound to the validate phase and unfortunately the file does not exist by this time. The zip file is generated by ant task that is bound to generate-resources mvn phase.

Question

Is there any way to make the mvn enforcer to run after generate-resources? Or to put it another way, how can I verify a build post-condition instead pre-condition?

Was it helpful?

Solution

omg, adding <phase>verify</phase> worked for me:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <executions>
      <execution>
        <id>enforce-file-size</id>
        <phase>verify</phase>
        <goals>
          <goal>enforce-once</goal>
        </goals>
        <configuration>
          <rules>
            <requireFilesSize>
              <maxsize>419430400</maxsize> <!-- the final zip should not exceed 400 MB -->
              <files>
               <file>${project.build.outputDirectory}.zip</file>
              </files>
            </requireFilesSize>
          </rules>
          <fail>true</fail>
        </configuration>
      </execution>
    </executions>
  </plugin>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top