简体   繁体   中英

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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM