简体   繁体   English

如何使maven enforcer插件在指定阶段运行?

[英]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: 我想确保生成的zip文件的文件大小不超过400 MB,所以我创建了这个规则:

      <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. 但是, mvn enforcer默认绑定到validate阶段,遗憾的是此时该文件不存在。 The zip file is generated by ant task that is bound to generate-resources mvn phase. zip文件由绑定到generate-resources mvn阶段的ant任务generate-resources

Question

Is there any way to make the mvn enforcer to run after generate-resources ? 有没有办法让mvn enforcergenerate-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: omg,添加<phase>verify</phase>为我工作:

  <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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