是否可以强制Maven 2要求在命令行上指定一个属性?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (116)

例如

mvn -Denv=test
提问于
用户回答回答于

在Maven中

<project>
...
    <profiles>
        <profile>
            <id>failure_profile</id>
            <activation>
                <property>
                    <name>!env</name>
                </property>
            </activation>
        </profile>
    </profiles>
</project>

然后

<profile>
    <id>failure_profile</id>
    ...
    <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <executions>
              <execution>
                <id>enforce</id>
                <goals>
                  <goal>enforce</goal>
                </goals>
                <configuration>
                  <rules>
                    <AlwaysFail/>
                  </rules>
                  <fail>true</fail>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
</profile>

如果不提供-denv构建

[INFO] [enforcer:enforce {execution: enforce}]
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.AlwaysFail failed with message:
Always fails!
[INFO] ---------------------------------------------------------
[ERROR] BUILD ERROR

扫码关注云+社区

领取腾讯云代金券