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

时间:2013-10-03 14:58:44

标签: maven maven-plugin maven-enforcer-plugin

我想确保生成的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>

但是, mvn enforcer 默认绑定到validate阶段,遗憾的是此时该文件不存在。 zip文件由绑定到generate-resources mvn阶段的ant任务生成。

问题

有没有办法让 mvn enforcer generate-resources之后运行?换句话说,如何验证构建后置条件而不是预先条件?

1 个答案:

答案 0 :(得分:5)

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>