首页 > 解决方案 > 强制 Maven 命令行参数

问题描述

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

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

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

谢谢。

标签: javaspringmavencommand-line

解决方案


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>


推荐阅读