sbt value not found addSbtPlugin when installing onejar plugin - plugins

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.

Related

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?
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.

Sbt 0.13 to 1.0 - What's the replacement for onLoad in Global for multiprojects?

I am trying to create a new project, this time with sbt 1.0.2 instead of 0.13.x which I used for quite some time now.
There I had a multi-project setup comparable to https://github.com/vmunier/akka-http-with-scalajs-example/blob/master/build.sbt
My problem now is that I always get [error] (projectname/compile:bgRun) No main class detected. when I try to run sbt run
Here is my current build.sbt file:
lazy val generalSettings = Seq(
name := "awesomeproject.tld",
version := "0.1",
scalaVersion := "2.12.3"
)
lazy val client = (project in file("modules/client"))
.settings(generalSettings: _*)
.settings(
name := "client",
libraryDependencies ++= Seq(
"com.lihaoyi" %%% "scalatags" % "0.6.5",
"org.scala-js" %%% "scalajs-dom" % "0.9.2"
)
, scalaJSUseMainModuleInitializer := true
)
.enablePlugins(ScalaJSPlugin, ScalaJSWeb)
.dependsOn(sharedJS)
lazy val server = (project in file("modules/server"))
.settings(generalSettings: _*)
.settings(
name := "server",
scalaJSProjects := Seq(client),
pipelineStages in Assets := Seq(scalaJSPipeline),
// triggers scalaJSPipeline when using compile or continuous compilation
//compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value,
WebKeys.packagePrefix in Assets := "public/",
//managedClasspath in Runtime += (packageBin in Assets).value,
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.5.4",
"com.typesafe.akka" %% "akka-testkit" % "2.5.4" % Test,
"com.typesafe.akka" %% "akka-stream" % "2.5.4",
"com.typesafe.akka" %% "akka-stream-testkit" % "2.5.4" % Test,
"com.typesafe.akka" %% "akka-http" % "10.0.10",
"com.typesafe.akka" %% "akka-http-testkit" % "10.0.10" % Test,
"ch.qos.logback" % "logback-classic" % "1.2.3",
"com.typesafe.scala-logging" %% "scala-logging" % "3.7.2",
"com.lihaoyi" %% "scalatags" % "0.6.5",
"com.vmunier" %% "scalajs-scripts" % "1.1.0"
)
, mainClass := Some("tld.awesomeproject.Main")
)
.dependsOn(sharedJVM)
lazy val shared = (crossProject.crossType(CrossType.Pure) in file("modules/shared"))
.settings(generalSettings: _*)
.settings(
name := "shared"
)
lazy val sharedJS = shared.js
lazy val sharedJVM = shared.jvm
As you can see I tried to solve the problem with setting it explicitly with mainClass := Some("tld.awesomeproject.Main") in the subproject. I also tried to set a root project explicitly, make it dependOn the server but no luck.
I guess the real problem here is, that
onLoad in Global := (Command.command("project server", _: State)) compose (onLoad in Global) does not work in sbt 1.0.2 anymore.
I checked the Command class, but I am not wiser after. There simply is no more method that gives back a state.
Can anyone shed like on this? What I want is to run a server that sends some javascript to the client... that shouldn't be black magic, in fact everything worked like a charm in my 0.13. project.
This should work:
onLoad in Global ~= (_ andThen ("project server" :: _))
Reference: https://github.com/sbt/sbt/issues/1224#issuecomment-331840364

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