Search code examples
mavenintellij-ideaintellij-14

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


Solution

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

    enter image description here