I'm trying to add scalameter tests to an existing project of mine. According to the docs, I can add this code to my build.sbt and then I should be able to invoke sbt bench:test
and have only the benchmarks run. However, when I run the command, I get this error:
$ sbt "bench:test"
[info] welcome to sbt 1.8.2 (N/A Java 17.0.6)
<snip>
[error] No such setting/task
[error] bench:test
[error]
When I list the tasks in the sbt shell, I see no sign of the bench task. How can I get this working?
I've created the benchmark file in src/bench/scala/EndpointBenchmark.scala
in case that's important. I'm not totally sure where the test should reside.
I had a look at the sbt docs and googled the error above, but I couldn't find anything mentioning how to deal with the case where the setting/task isn't found at all. I assume I need to add it into the root project somehow?
build.sbt
val scalaVersionString = "2.13.10"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := scalaVersionString
val AkkaVersion = "2.7.0"
val AkkaHttpVersion = "10.5.0"
lazy val root = (project in file("."))
.settings(
name := "sample_project"
)
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor-typed" % AkkaVersion,
"com.typesafe.akka" %% "akka-stream" % AkkaVersion,
"com.typesafe.akka" %% "akka-http" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http-testkit" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-stream-testkit" % AkkaVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % AkkaHttpVersion,
"com.maximeroussy.invitrode" % "invitrode" % "2.0.2",
"org.scalatest" %% "scalatest" % "3.2.15" % Test,
"com.storm-enroute" %% "scalameter" % "0.21" % Test,
"ch.qos.logback" % "logback-classic" % "1.4.5"
)
lazy val Benchmark = config("bench") extend Test
/** This allows running ScalaMeter benchmarks in separate sbt configuration.
* It means, that when you want run your benchmarks you should type `bench:test` in sbt console.
*/
lazy val basic = (project in file("."))
.settings(Defaults.coreDefaultSettings ++ Seq(
name := "sample_project_benchmarks",
scalaVersion := scalaVersionString,
scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-Xlint"),
publishArtifact := false,
libraryDependencies ++= Seq(
"com.storm-enroute" %% "scalameter" % "0.21" % "bench"
),
resolvers ++= Seq(
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
"Sonatype OSS Releases" at "https://oss.sonatype.org/content/repositories/releases"
),
testFrameworks += new TestFramework("org.scalameter.ScalaMeterFramework"),
Benchmark / parallelExecution := false,
logBuffered := false
)
) configs(
Benchmark
) settings(
inConfig(Benchmark)(Defaults.testSettings): _*
)