在 IntelliJ 中,如何在使用 Maven 构建时传递命令行变量(TestNG 运行 配置)?

In IntelliJ, how do I pass command line variables when building with Maven (TestNG run configuration)?

我正在尝试执行以下操作,但在具有 TestNG 运行 配置的 IntelliJ 中:

mvn clean install -Dfoo=bar

因此,foo 系统 属性 的值应该是 bar:

System.out.println(System.getProperty("foo"));
======
bar

我用谷歌搜索过的所有可能的答案要么告诉我将变量硬编码到我的 pom.xml 中(我不能这样做),要么告诉我“just set it in Edit Configurations...”而不显示正确设置的变量看起来像。我也翻阅了 IntelliJ 手册。

我在 Run/Debug Configurations/Parameters 选项卡和 Run/Debug Configurations/Environment 变量中尝试了 "foo" 的所有逻辑名称,例如 Dfoo-Dfoo.

使用 Maven 配置而不是 TestNG 配置。您仍然可以 运行 从 Maven 配置中进行 TestNG 测试: