Cannot pass arguments using sbt to gatling simulation - scala

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?

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.

Related

SBT does not propagate changes in webapp when using xsbt-web-plugin and JRebel

The set up is as follows:
Lift Web
xsbt-web-plugin
sbt-jrebel-plugin
JRebel
My static web files (html, etc) are in /src/webapp
I run
# sbt
> jetty:start
> ~compile
Problem: even thought SBT detects changes in static files, as well as JRebel logs indicating that it also see them, the changes are not propagated into /target/webapp. Recompilation and reload of scala files works fine.
build.sbt
organization := "serendipity"
name := "story-telling"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies ++= {
val liftVersion = "3.0-RC3"
Seq(
"net.liftweb" %% "lift-webkit" % liftVersion % "compile",
"net.liftweb" %% "lift-mapper" % liftVersion % "compile",
"org.eclipse.jetty" % "jetty-webapp" % "9.3.13.v20161014",
"com.h2database" % "h2" % "1.4.193"
)
}
enablePlugins(JettyPlugin)
seq(jrebelSettings: _*)
jrebel.webLinks += (sourceDirectory in Compile).value / "webapp"
jrebel.classpath <<= Seq(Keys.classDirectory in Compile).join
jrebel.enabled := true
javaOptions in Jetty ++= Seq(
"-javaagent:/opt/jrebel/jrebel.jar",
"-noverify",
"-XX:+UseConcMarkSweepGC",
"-XX:+CMSClassUnloadingEnabled",
"-Drebel.log=debug",
"-Drebel.log.file=/home/anton/.jrebel/jrebel.log"
)
Just run instead:
> jetty:start
> ~compile
as far as i understand this is a workaround rather than the proper solution

Can not create a multi project build

I am trying to create a Play application with a back end and a front end(using Scala.js). I separated the code into client and server folders.
For creating a Multi Project Build I looked at this http://www.scala-sbt.org/release/docs/Multi-Project.html and make my build.sbt like this:
name := """ScalaWeb"""
version := "1.0-SNAPSHOT"
lazy val commonSettings = Seq(
scalaVersion := "2.11.7",
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
specs2 % Test
),
libraryDependencies ++= Seq(
"org.sorm-framework" % "sorm" % "0.3.19",
"org.scala-lang" % "scala-compiler" % scalaVersion.value force(),
"com.h2database" % "h2" % "1.3.148"
),
libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.1.0",
/*libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.1.0",
libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.12"
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.1.3"*/
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases",
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator,
scalacOptions += "-Ylog-classpath",
// use this if you just want jawn's parser, and will implement your own facade
libraryDependencies += "org.spire-math" %% "jawn-parser" % "0.8.3",
// use this if you want jawn's parser and also jawn's ast
libraryDependencies += "org.spire-math" %% "jawn-ast" % "0.8.3",
//for reading Json libraries
libraryDependencies += "org.scalaj" %% "scalaj-http" % "2.2.1"
)
lazy val server = (project in file("server")).settings(
commonSettings: _*
).enablePlugins(PlayScala)
lazy val client = (project in file("client")).settings(
commonSettings: _*
).enablePlugins(PlayScala)
fork in run := true
So basically I placed all dependencies into commonSettings and the imported that into the client and server projects.
However, I am getting this error:
[error] (scalaweb/compile:backgroundRun) No main class detected.
Why is this occuring?
Have I set up my build.sbt incorrectly?
That's because your root project (scalaweb) doesn't have a main class.
You can either:
run server's run command by doing: server/run
aggregate client and server under root project
(http://www.scala-sbt.org/0.13/docs/Multi-Project.html#Aggregation)
This might do what you wish.

error: not found: value StartScriptPlugin StartScriptPlugin.stage in Compile := Unit

First I need to say, I'm Scala and SBT beginner so this is my first project with it. I try to deploy scala app on Heroku. I'm getting this error:
error: not found: value StartScriptPlugin StartScriptPlugin.stage in Compile := Unit
Here is my build.sbt. What is wrong with it? I know that is something with StartScriptPlugin.stage in Compile := Unit but I found some examples and they always use it this way. Thanks
name := "Survey server"
version := "1.0"
scalaVersion := "2.9.2"
resolvers ++= Seq("repo.codahale.com" at "http://repo.codahale.com", Classpaths.typesafeResolver)
addSbtPlugin("com.typesafe.startscript" % "xsbt-start-script-plugin" % "0.5.3")
StartScriptPlugin.stage in Compile := Unit
EclipseKeys.withSource := true
libraryDependencies ++= Seq(
"net.databinder" %% "unfiltered-filter" % "0.6.3",
"net.databinder" %% "unfiltered-jetty" % "0.6.3",
"net.databinder.dispatch" %% "core" % "0.9.0",
"com.codahale" % "jerkson_2.9.1" % "0.5.0",
"org.scalaquery" % "scalaquery_2.9.1" % "0.10.0-M1",
"postgresql" % "postgresql" % "9.1-901.jdbc4" )
You need to tell SBT that your project uses the StartScriptPlugin. This is done by using the addSbtPlugin command in project/plugins.sbt. This is all explained in the SBT documentation:
https://github.com/harrah/xsbt/wiki/Getting-Started-Using-Plugins
The documentation for the plugin that you are trying to use even tells you exactly what you need to add to project/plugins.sbt. For SBT 0.11, this would be:
resolvers += Classpaths.typesafeResolver
addSbtPlugin( "com.typesafe.startscript" % "xsbt-start-script-plugin" % "0.5.2" )
See https://github.com/typesafehub/xsbt-start-script-plugin

sbt value not found addSbtPlugin when installing onejar plugin

I'm trying to install the one-jar sbt plugin but am getting the following error:
sbt/project/plugins/plugins.sbt:5: error: not found: value addSbtPlugin
addSbtPlugin("com.github.retronym" % "sbt-onejar" % "0.6")
Here is the relevant contents of my sbt/build.sbt file:
seq(com.github.retronym.SbtOneJar.oneJarSettings: _*)
name := "dsg_nlp"
version := "0.11"
scalaVersion := "2.9.1"
libraryDependencies ++= Seq( "org.scalatest" %% "scalatest" % "1.6.1" % "test" )
libraryDependencies += "commons-lang" % "commons-lang" % "2.6"
traceLevel in run := 0
fork in run := true
javaOptions in run ++= Seq("-Xmx7G", "-agentlib:hprof=cpu=samples,depth=12", "-server", "-enableassertions")
scalacOptions ++= Seq("-optimize")
mainClass in (one-jar, Compile, packageBin) := Some("Test")
And the contents of my project/plugins/plugins.sbt file:
resolvers += "retronym-releases" at "http://retronym.github.com/repo/releases"
resolvers += "retronym-snapshots" at "http://retronym.github.com/repo/snapshots"
addSbtPlugin("com.github.retronym" % "sbt-onejar" % "0.6")
I would suggest the following changes to the code above:
Make sure you have only one setting per line. So split
libraryDependencies ++= Seq( "org.scalatest" %% "scalatest" % "1.6.1" % "test" )
libraryDependencies += "commons-lang" % "commons-lang" % "2.6"
into two lines.
The last line should read
mainClass in oneJar := Some("Test")
if you want to use another mainClass for the oneJar-Plugin. If it's the same as in the compile scope. You may as well write this as
mainClass in Compile := Some("Test")
but do not specifiy both.
Your project directory structure should look like this:
Project-Root /
|-- build.sbt
|-- project/plugins.sbt
the actual names of the sbt-files don't matter they just have to end in .sbt.

How to fallback Scala version for SBT dependencies?

I have dependencies in my build.sbt that don't have specific builds for the Scala 2.9.0-1 I'm using, instead I'm supposed to use the build for 2.9.0. How to configure the build so that it determines that without specifying the exact version for each dependency? For instance subcut doesn't have a build for 2.9.0-1.
Some lines off my build.sbt:
...
scalaVersion := "2.9.0-1"
libraryDependencies ++= Seq(
"org.scala-tools" %% "subcut" % "0.8"
)
...
I'd rather avoid this:
"org.scala-tools" % "subcut_2.9.0" % "0.8"
Something along the lines of specifying multiple versions it'd try in the specified order.
Here's what I've done:
libraryDependencies <++= (scalaVersion) { (v) =>
val scalaVersionString = v match {
case "2.9.0-1" => "2.9.0"
case _ => v
}
Seq(
"org.scala-tools.testing" % ("scalacheck_" + scalaVersionString) % "1.8" % "test" withSources,
"org.specs2" %% "specs2" % "1.3" % "test" withSources,
"com.github.dmlap" %% "sizeof" % "0.1" % "test" from "http://cloud.github.com/downloads/dmlap/jvm-sizeof/jvm-sizeof-0.1.jar"
)
}