Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to do the following, but in IntelliJ with a TestNG run configuration:

mvn clean install -Dfoo=bar

So, the value for the foo system property should be bar:

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

All potential answers I've googled either tell me to hardcode variables into my pom.xml (which I can't do) or say to "just set it in Edit Configurations..." without showing what a properly set variable looks like. I dug through the IntelliJ manual too.

I tried all the logical names for "foo" in both Run/Debug Configurations/Parameters tab and Run/Debug Configurations/Environment Variables, such as Dfoo and -Dfoo.

Run/Debug Configurations and Environment Variables

like image 874
JaneGoodall Avatar asked Sep 14 '25 22:09

JaneGoodall


1 Answers

Use a Maven configuration instead of a TestNG configuration. You can still run your TestNG tests from the Maven configuration:

enter image description here

like image 145
Meo Avatar answered Sep 19 '25 20:09

Meo