Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make maven enforcer plugin to run in a specified phase?

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?

like image 338
Jiri Kremser Avatar asked Oct 03 '13 14:10

Jiri Kremser


1 Answers

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>
like image 70
Jiri Kremser Avatar answered Oct 23 '22 02:10

Jiri Kremser