'Cannot pass arguments using sbt to gatling simulation

Regarding to Gatling SBT execute a specific simulation topic is there any way to pass argument to simulation?

I've been trying passing command from any CLI like:

sbt -Dx=1 -Dy=2 -Dz=3 "gatling:testOnly fooSimulation"

and:

sbt "-Dx=1 -Dy=2 -Dz=3 gatling:testOnly fooSimulation"

and all similar variations, but in result it gives just a null value.

Same thing I was trying to do in sbt shell, because I use it as well, but no success at all. Maybe my specific configuration in build.sbt is the main reason why it doesn't work. Nevertheless I do not want to pass the arguments in config file, it should be dynamic.

build.sbt

name := "Gatling"
version := "0.1"
scalaVersion := "2.12.11"

enablePlugins(GatlingPlugin)

fork := true

scalacOptions := Seq(
  "-encoding", "UTF-8", "-target:jvm-1.8", "-deprecation",
  "-feature", "-unchecked", "-language:implicitConversions", "-language:postfixOps")

libraryDependencies += "io.gatling.highcharts" % "gatling-charts-highcharts" % "3.3.1" % Test
libraryDependencies += "io.gatling" % "gatling-test-framework" % "3.3.1" % Test
libraryDependencies += "org.json4s" % "json4s-native_2.12" % "3.6.7" % Test
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % Test
libraryDependencies += "com.microsoft.sqlserver" % "mssql-jdbc" % "7.2.2.jre8" % Test
libraryDependencies += "org.springframework.boot" % "spring-boot-starter" % "2.3.5.RELEASE" % Test
libraryDependencies += "com.typesafe" % "config" % "1.4.1" % Test

Test / javaOptions += "-DpropertiesFile=./src/test/resources/application.properties"

plugins.sbt

addSbtPlugin("io.gatling" % "gatling-sbt" % "3.2.0")

Example code:

class FooSimulation extends Simulation {

  before {
    println(s"x=${System.getProperty("x")}")
    println(s"y=${System.getProperty("y")}")
    println(s"z=${System.getProperty("z")}")
  }

  setUp(
    scenario("Foo")
      .exec( foo chain builder )
      .inject( foo injection )
  ).protocols( foo protocol )
}

Additionally my sbt shell is running with prefix sbt:gatling, maybe this is the reason?



Solution 1:[1]

sbt -Dx=1 -Dy=2 -Dz=3 "gatling:testOnly fooSimulation" is correct.

But the modern sbt syntax is sbt -Dx=1 -Dy=2 -Dz=3 "Gatling/testOnly fooSimulation".

If it doesn't work, you probably have a typo somewhere, or possibly your version of sbt and Gatling are way too old and your should upgrade.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stéphane LANDELLE