【问题标题】:Making Maven command line parameter mandatory强制 Maven 命令行参数
【发布时间】:2018-10-17 06:02:55
【问题描述】:

我正在编写一个小项目来了解 Maven 和 Spring Framework。要运行我的项目,我运行以下命令:

clean install exec:java -e -DinputFolder=src/main/resources/testCases

有没有办法在运行时强制 inputFolder 参数?

谢谢。

【问题讨论】:

  • 首先:你真正想要实现什么?你想运行测试吗?为什么要把它们放到 src/main/resources 中?
  • 其次:您可以将插件执行添加到您的 pom.xml 中。然后在执行构建时自动调用它们。

标签: java spring maven command-line


【解决方案1】:

Maven Enforcer Plugin 可用于要求为您的构建配置属性。 requireProperty 规则将完成这项工作。

<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>3.0.0-M1</version> <executions> <execution> <id>enforce-property</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <requireProperty> <property>inputFolder</property> <message>inputFolder property must be set</message> </requireProperty> </rules> <fail>true</fail> </configuration> </execution> </executions> </plugin> </plugins> </build> [...] </project>

【讨论】: