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"
)
}
Related
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.
i am using scala 2.13 and i have to use Gatling load tests, Gatling does not support Scala-2.13 for that i looked into sbt cross build and how to cross build library dependency
i have two Gatling dependencies
"io.gatling.highcharts" % "gatling-charts-highcharts" % "3.3.1",
"io.gatling" % "gatling-test-framework" % "3.3.1"
these libraries support Scala 2.12 for that i am doing something like this
build.sbt
lazy val scala212 = "2.12.10"
lazy val scala213 = "2.13.1"
scalaVersion := scala213
lazy val supportedScalaVersions = List(scala213, scala212)
lazy val root = (project in file("."))
.settings(
crossScalaVersions := supportedScalaVersions,
)
libraryDependencies ++= Seq(
"org.mongodb.scala" %% "mongo-scala-driver" % "2.8.0",
"com.typesafe.akka" %% "akka-actor" % "2.6.3",
"com.typesafe.akka" %% "akka-stream" % "2.6.3"
)
libraryDependencies ++= (scalaBinaryVersion.value match {
case "2.12.10" => Seq(
"io.gatling.highcharts" % "gatling-charts-highcharts" % "3.3.1",
"io.gatling" % "gatling-test-framework" % "3.3.1"
)
case _ => Seq()
}
)
Sbt is not downloading the Gatling dependencies and sbt update command does not show any error it looks like the case 2.12.10 match part is not even executed
what is the right way to do this ? i want to write Gatling simulations in test directory
You got it almost right but scalaBinaryVersion is 2.12 in your case. scalaVersion.value is what you are looking for.
i can't import the sbt and typesafe libraries into build.sbt in IntelliJ.
The dependencies of sbt and typesafe are in the plugin.sbt file. In the file plugin.sbt also I have the addSbtPlugin method in red:
plugin.sbt
while the import of the libraries are inside the build.sbt file.
build.sbt
My
How can I do?
Update
The build.sbt file is this:
import com.typesafe.sbt.license.{DepModuleInfo, LicenseCategory, LicenseInfo}
import sbt._
import scala.io.Source
// Core library versions (the ones that are used multiple times)
val sparkVersion: String = "2.3.1"
val slf4jVersion: String = "1.7.25"
val logbackVersion: String = "1.2.3"
// Artifactory settings
val artifactoryRealm: String = "artifactory-espoo1.int.net.nokia.com"
val artifactoryUrl: String = s"https://$artifactoryRealm/artifactory/"
val artifactoryUser: Option[String] = sys.env.get("ARTIFACTORY_USER")
val artifactoryPassword: Option[String] = sys.env.get("ARTIFACTORY_PASSWORD")
// Project variables
val organizationId: String = "com.nokia.gs.npo.ae"
val rootPackage: String = organizationId + ".rfco"
// Base settings shared across modules
val baseSettings: Seq[SettingsDefinition] = Seq(
organization := organizationId,
version := Source.fromFile(file("VERSION")).mkString.trim + sys.env.getOrElse("VERSION_TAG", ""),
scalaVersion := "2.11.12",
buildInfoUsePackageAsPath := true,
scalafmtOnCompile in ThisBuild := false, // just invoke `sbt scalafmt` before commits!
parallelExecution in ThisBuild := false,
fork in Test := true,
testForkedParallel in Test := true,
logLevel in test := util.Level.Info,
coverageMinimum := sys.env.getOrElse("COVERAGE_MINIMUM", "80.0").toDouble,
coverageFailOnMinimum := true,
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-sql" % sparkVersion % Provided,
"org.apache.spark" %% "spark-hive" % sparkVersion % Provided,
"org.slf4j" % "slf4j-api" % slf4jVersion % Compile,
"com.nokia.gs.ncs.chubs.common" %% "spark-commons" % "0.5.10" % Compile,
"com.nokia.gs.ncs.chubs.common" %% "lang" % "0.2.0" % Compile,
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.9.8" % Compile,
"com.typesafe.play" %% "play-json" % "2.7.1" % Compile,
"org.apache.commons" % "commons-csv" % "1.7" % Compile,
"org.scalatest" %% "scalatest" % "3.0.5" % Test,
"ch.qos.logback" % "logback-classic" % logbackVersion % Test,
"ch.qos.logback" % "logback-core" % logbackVersion % Test,
"org.apache.spark" %% "spark-hive-thriftserver" % sparkVersion % Test,
"com.github.tomakehurst" % "wiremock-standalone" % "2.22.0" % Test
),
excludeDependencies ++= Seq(
"com.fasterxml.jackson.module" % "jackson-module-scala",
"org.slf4j" % "slf4j-log4j12",
"org.hamcrest" % "hamcrest-core",
"javax.servlet" % "servlet-api"
),
publishTo := {
Some("Artifactory Realm" at artifactoryUrl + sys.env.getOrElse("ARTIFACTORY_LOCATION", "ava-maven-snapshots-local"))
},
packagedArtifacts in publish ~= { m =>
val classifiersToExclude = Set(Artifact.SourceClassifier)
m.filter({ case (art, _) => art.classifier.forall(c => !classifiersToExclude.contains(c)) })
},
(artifactoryUser, artifactoryPassword) match {
case (Some(user), Some(password)) =>
credentials += Credentials("Artifactory Realm", artifactoryRealm, user, password)
case _ =>
println("[info] USERNAME and/or PASSWORD is missing for publishing to Artifactory")
credentials := Seq()
}
)
By looking at the build.sbt your plugins.sbt should at least contain these lines:
addSbtPlugin("com.typesafe.sbt" % "sbt-license-report" % "1.2.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.2.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
I solved import sbt, creating a new project on IntelliJ IDea and importing the source files into the project I created. Oddly now it does the import. Before, however, I opened the source folder with the code from IntelliJ, but not made the import of sbt.
build.sbt
I only have to resolve type safe dependencies, but it is a problem with external and private dependencies.
Thanks for your help
I have a MergeStrategy problem. How do I resolve it? Why are all those squiggly lines there?
The error message is Type mismatch, expected: String => MergeStrategy, actual: String => Any
I am new to scala, so, I have no idea what that syntax means. I have tried copying different merge strategies from all over stackoverflow and none and them work.
I have scala version 2.12.7 and sbt version 1.2.6.
My build.sbt looks like this:
lazy val root = (project in file(".")).
settings(
name := "bigdata-mx-2",
version := "0.1",
scalaVersion := "2.12.7",
mainClass in Compile := Some("Main")
)
libraryDependencies ++= Seq(
"org.apache.hadoop" % "hadoop-core" % "1.2.1",
"org.apache.parquet" % "parquet-hadoop" % "1.10.0",
"junit" % "junit" % "4.12" % Test,
"org.scalatest" %% "scalatest" % "3.2.0-SNAP10" % Test,
"org.scalacheck" %% "scalacheck" % "1.14.0" % Test,
"org.scala-lang" % "scala-library" % "2.12.7"
)
// Where do I put this thing:
assemblyMergeStrategy in assembly := {
case PathList("META-INF", xs # _*) => MergeStrategy.discard
case x => MergeStrategy.first
}
Maybe I'm not putting it into the right place, where does it go?
I need to cross-build a project with both Scala 2.10 and 2.11 (and ultimately 2.12 also). Some packages that were part of 2.10, for example parser-combinators, are packaged independently in 2.11. Thus they are not required to be mentioned in the 2.10 build but are required in 2.11. Furthermore, there may be more than one such package, which are required to use a common version.
I found the documentation re: cross-building on the SBT site to be somewhat lacking in helpfulness here. And, although, there are several StackOverflow Q&As which relate to this subject, I could not find one that addressed this specific point.
The solution is as follows (showing only the relevant part of build.sbt):
scalaVersion := "2.10.6"
crossScalaVersions := Seq("2.10.6","2.11.8")
val scalaModules = "org.scala-lang.modules"
val scalaModulesVersion = "1.0.4"
val akkaGroup = "com.typesafe.akka"
lazy val akkaVersion = SettingKey[String]("akkaVersion")
lazy val scalaTestVersion = SettingKey[String]("scalaTestVersion")
akkaVersion := (scalaBinaryVersion.value match {
case "2.10" => "2.3.15"
case "2.11" => "2.4.1"
})
scalaTestVersion := (scalaBinaryVersion.value match {
case "2.10" => "2.2.6"
case "2.11" => "3.0.1"
})
libraryDependencies ++= (scalaBinaryVersion.value match {
case "2.11" => Seq(
scalaModules %% "scala-parser-combinators" % scalaModulesVersion,
scalaModules %% "scala-xml" % scalaModulesVersion,
"com.typesafe.scala-logging" %% "scala-logging" % "3.4.0"
)
case _ => Seq()
}
)
libraryDependencies ++= Seq(
akkaGroup %% "akka-actor" % akkaVersion.value % "test",
"org.scalatest" %% "scalatest" % scalaTestVersion.value % "test"
)
Note that this solution also addresses the problem of how to set the version of a dependency(ies) according to the binary version. I think this may be addressed elsewhere in Stackoverflow but here it is all in the same place.