【问题标题】:Maven: How do I enforce property inclusion for a life cycle phase?Maven:如何在生命周期阶段强制包含属性?
【发布时间】:2011-12-08 18:54:58
【问题描述】:

我正在使用 Maven 3.0.3。如果有人运行包含“验证”阶段的 Maven 任务,我想确保定义了一个属性“tomcat.manager.url”,如果没有,则抛出错误。但是,如果有人没有运行包含验证的命令(例如 mvn test),我不想抛出任何错误。

我该怎么做?

谢谢,- 戴夫

【问题讨论】:

    标签: maven maven-2 properties


    【解决方案1】:

    您可以将强制插件 (docs) 设置为在“验证”阶段执行,并使用需要设置该插件的规则,配置如下所示:

    <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <version>1.0.1</version>
            <executions>
              <execution>
                <id>enforce-property</id>
                <goals>
                  <goal>enforce</goal>
                </goals>
                <phase>verify</phase>
                <configuration>
                  <rules>
                    <requireProperty>
                      <property>tomcat.manager.url</property>
                      <message>You must set a tomcat manager url</message>
                    </requireProperty>
                  </rules>
                  <fail>true</fail>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    

    由于插件只会在验证阶段执行,因此除非您正在运行达到该阶段的构建,否则不会进行检查。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-05
      • 2016-08-05
      • 1970-01-01
      • 2021-01-25
      • 1970-01-01
      • 2017-11-10
      相关资源
      最近更新 更多