How can I use the Play Framework in a multi-project? - scala

I am struggling to find any information on how to use the Play Framework in a multi-project where the root project is a plain SBT one. Basically this is my project's layout:
/
- common
- some-other-projects
- my-play-project
- - app
- - - controllers
- - conf
- - - routes
- build.sbt
I can start the application by running my-play-project/run in the SBT console, but when I try to visit any page, I get a 500 and this error is logged:
[error] /someorg/backend/cms/conf/routes: package router does not exist
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error] symbol: class ReversePostController
[error] location: package controllers
[error] /someorg/backend/cms/conf/routes: package controllers.javascript does not exist
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error] symbol: class ReversePostController
[error] location: package controllers
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error] symbol: variable RoutesPrefix
[error] location: class controllers.routes
[error] /someorg/backend/cms/conf/routes: package controllers.javascript does not exist
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error] symbol: variable RoutesPrefix
[error] location: class controllers.routes.javascript
[error] (cms/compile:compileIncremental) javac returned nonzero exit code
[info] Compiling 6 Scala sources and 1 Java source to /someorg/backend/cms/target/classes...
[error] /someorg/backend/cms/conf/routes: package router does not exist
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error] symbol: class ReversePostController
[error] location: package controllers
[error] /someorg/backend/cms/conf/routes: package controllers.javascript does not exist
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error] symbol: class ReversePostController
[error] location: package controllers
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error] symbol: variable RoutesPrefix
[error] location: class controllers.routes
[error] /someorg/backend/cms/conf/routes: package controllers.javascript does not exist
[error] /someorg/backend/cms/conf/routes: cannot find symbol
[error] symbol: variable RoutesPrefix
[error] location: class controllers.routes.javascript
[error] (cms/compile:compileIncremental) javac returned nonzero exit code
[error] application -
! #6pi9jna82 - Internal server error, for (GET) [/posts] ->
play.sbt.PlayExceptions$CompilationException: Compilation error[package router does not exist]
at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27)
at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27)
at scala.Option.map(Option.scala:145)
at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:49)
at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44)
at scala.Option.map(Option.scala:145)
at play.sbt.run.PlayReload$.taskFailureHandler(PlayReload.scala:44)
at play.sbt.run.PlayReload$.compileFailure(PlayReload.scala:40)
at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)
at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)
Is there anything obvious I am missing that breaks this project? The controller is defined in the simplest possible way as explained in the documentation. The same goes for the only route I provide:
# Route
GET /posts controllers.PostController.list
// Controller
package controllers
import play.api.mvc.{Action, Controller}
class PostController extends Controller {
def list = TODO
}
I'm using Play Framework 2.5.1 and the project build is defined as follows:
lazy val resolvers = ...
lazy val projectSettings = Seq(
organization := "some-organization",
scalaBinaryVersion := "2.11",
scalaVersion := "2.11.7",
externalResolvers := resolvers,
moduleConfigurations := Seq(),
retrieveManaged := true,
concurrentRestrictions in Global += Tags.limit(Tags.Test, 1),
transitiveClassifiers in Scope.GlobalScope := Seq("sources"),
ivyLoggingLevel := UpdateLogging.Quiet,
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"),
crossPaths := false,
publishMavenStyle := true,
publishArtifact in (Compile, packageDoc) := false,
publishArtifact in (Test, packageDoc) := false,
javacOptions := Seq("-source", "1.8", "-target", "1.8", "-encoding", "utf8"),
javaOptions := Seq("-server", "-XX:ReservedCodeCacheSize=192m", "-Xss2m"),
javaOptions in Test := Seq("-server", "-Xmx2g", "-XX:ReservedCodeCacheSize=192m", "-Xss2m"),
testFrameworks := Seq(TestFrameworks.ScalaTest, TestFrameworks.Specs2),
noTestCompletion(),
scalacOptions := Seq(
"-deprecation",
"-optimize",
"-unchecked",
"-encoding", "utf8",
"-target:jvm-1.8",
"-Xlog-reflective-calls",
"-feature",
"-language:_"
) ++ Seq(
"by-name-right-associative",
"delayedinit-select",
"doc-detached",
"inaccessible",
"missing-interpolator",
"nullary-override",
"option-implicit",
"package-object-classes",
"poly-implicit-overload",
"private-shadow",
"unsound-match"
).map(x => s"-Xlint:$x"),
compileOrder := CompileOrder.JavaThenScala,
fork in Test := true,
testOptions in Test := Seq(Tests.Filter(testName => testName.endsWith("Test") || testName.endsWith("Spec"))),
testOptions in Test += Tests.Argument("-oDF"),
testOptions in Test <+= (target in Test).map { t =>
val testDir = t / "test-reports"
val maybeJUnitXml = if (flag("sbt.test.nojunitxml")) Seq.empty else Seq("-u", testDir.getAbsolutePath)
Tests.Argument(TestFrameworks.ScalaTest, maybeJUnitXml: _*)
}
)
lazy val cms = (project in file("cms"))
.settings(projectSettings)
.dependsOn(common, commonTest % "test", model % compileTest)
.enablePlugins(PlayScala)
lazy val root = (project in file("."))
.settings(projectSettings)
.aggregate(common, some-other-projects, cms) // TODO: Remove web

Update:
Now that you've posted your build.sbt file, I think the problem is the compile order. javac fails because it cannot find the mentioned package.
Try to use the default Mixed compilation order.
I suspect that you didn't enable the sbt-play plugin in the my-play-project subproject and hence your routes file wasn't compiled to my-play-project/target/scala-2.11/routes/main/router
In my-play-project/build.sbt, add:
enablePlugins(PlayScala)

Try adding the Play plugin declaration to the root project at /project/plugins.sbt

Related

Adding SBT as a dependency in SBT file

I am writing few sbt tasks in a scala file. These SBT tasks will be imported into many other projects.
lazy val root = (project in file(".")).
settings(
inThisBuild(List(
organization := "com.example",
scalaVersion := "2.11.8",
version := "1.0.0"
)),
name := "sbttasks",
libraryDependencies ++= Seq(
"org.scala-sbt" % "sbt" % "1.0.0" % "provided"
)
)
I get a compilation error
error] java.lang.RuntimeException: Conflicting cross-version suffixes in: org.scala-lang.modules:scala-xml, org.scala-lang.modules:scala-parser-combinators
[error] at scala.sys.package$.error(package.scala:27)
[error] at sbt.librarymanagement.ConflictWarning$.processCrossVersioned(ConflictWarning.scala:39)
[error] at sbt.librarymanagement.ConflictWarning$.apply(ConflictWarning.scala:19)
[error] at sbt.Classpaths$.$anonfun$ivyBaseSettings$64(Defaults.scala:1995)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:39)
[error] at sbt.std.Transform$$anon$4.work(System.scala:66)
[error] at sbt.Execute.$anonfun$submit$2(Execute.scala:262)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error] at sbt.Execute.work(Execute.scala:271)
[error] at sbt.Execute.$anonfun$submit$1(Execute.scala:262)
[error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:174)
[error] at sbt.Completion
I don't want to write the custom tasks in build.sbt itself (as the SBT documentation shows) because then I won't be able to import my custom tasks into other projects.
To write reusable tasks that you can "import" in different projects, you need to make an sbt plugin.
If you have a multi-project build and want to reuse your tasks in the subprojects, you can create a file project/MyPlugin.scala with
import sbt._
import sbt.Keys._
object MyPlugin extends AutoPlugin {
override def trigger = noTrigger
object autoImport {
val fooTask = taskKey[Foo]("Foo description")
val barTask = taskKey[Bar]("Bar description")
}
import autoImport._
override lazy val projectSettings = Seq(
fooTask := { ??? },
barTask := { ??? }
)
}
Then to enable this plugin (i.e. make those tasks available) in a subproject, you can write this in your build.sbt:
lazy val subproject = (project in file("subproject"))
.enablePlugins(MyPlugin)
On the contrast, if you want to reuse these tasks in other unrelated projects, you need to make this plugin a separate project and publish it. It's a normal sbt project, but instead of an explicit sbt dependency, you write in its build.sbt:
sbtPlugin := true
And the code defining tasks goes to src/main/scala/ (like in a normal project).
You can read in detail about writing plugins in the sbt documentation.
Change version of "org.scala-sbt" to "1.0.0-M4"
lazy val root = (project in file(".")).
settings(
inThisBuild(List(
organization := "com.example",
scalaVersion := "2.11.8",
version := "1.0.0",
name := "sbttasks"
)),
libraryDependencies ++= Seq(
"org.scala-sbt" % "sbt" % "1.0.0-M4" % "provided"
)
)
For entire compatibility matrix check
https://mvnrepository.com/artifact/org.scala-sbt/main

Finch Hello World Error: Http not a member of com.twitter.finagle

I'm trying to use the scala finch library to build an API.
I have the following simple code:
package example
import io.finch._
import com.twitter.finagle.Http
object HelloWorld extends App {
val api: Endpoint[String] = get("hello") { Ok("Hello, World!") }
Http.serve(":8080", api.toService)
}
And a build.sbt file that looks like this:
name := "hello-finch"
version := "1.0"
scalaVersion := "2.10.6"
mainClass in (Compile, run) := Some("example.HelloWorld")
libraryDependencies ++= Seq(
"com.github.finagle" %% "finch-core" % "0.10.0"
)
// found here: https://github.com/finagle/finch/issues/604
addCompilerPlugin(
"org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full
)
When I compile and run the code I get this error message:
object Http is not a member of package com.twitter.finagle
[error] import com.twitter.finagle.Http
[error] ^
[error] /Users/jamesk/Code/hello_finch/hello-finch/src/main/scala/example/Hello.scala:8: wrong number of type arguments for io.finch.Endpoint, should be 2
[error] val api: Endpoint[String] = get("hello") { Ok("Hello, World!") }
[error] ^
[error] /Users/jamesk/Code/hello_finch/hello-finch/src/main/scala/example/Hello.scala:8: not found: value get
[error] val api: Endpoint[String] = get("hello") { Ok("Hello, World!") }
[error] ^
[error] /Users/jamesk/Code/hello_finch/hello-finch/src/main/scala/example/Hello.scala:10: not found: value Http
[error] Http.serve(":8080", api.toService)
[error] ^
[error] four errors found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 1 s, completed Aug 15, 2017 12:56:01 PM
At this point I'm running out of ideas, it looks like a good library but it's a pain getting it working. Any help would be very much appreciated.
I have updated your example to work with the last version of Finch: "com.github.finagle" %% "finch-core" % "0.15.1" and also Scala 2.12
the build.sbt file:
name := "hello-finch"
version := "1.0"
scalaVersion := "2.12.2"
mainClass in (Compile, run) := Some("example.HelloWorld")
libraryDependencies ++= Seq(
"com.github.finagle" %% "finch-core" % "0.15.1"
)
then, the src/main/scala/example/HelloWorld.scala file:
package example
import io.finch._
import com.twitter.finagle.Http
import com.twitter.util.Await
object HelloWorld extends App {
val api: Endpoint[String] = get("hello") { Ok("Hello, World!") }
Await.ready(Http.server.serve(":8080", api.toServiceAs[Text.Plain]))
}
Notice also that having Await.ready() is mandatory - your program would exit right away otherwise.

ScalaPB with Scala.js and Scala(jvm) - There were linking errors

I have multiple subprojects in my sbt, one being a server (base upon playframework) the other being the clientside (scala.js) and the third one being the communication between the two in form of protobuf (scalapb).
Now, this is my build.sbt:
lazy val generalSettings = Seq(
organization := "tld.awesomeness",
version := "0.0.1",
scalaVersion := "2.12.1"
)
val CrossDependencies = new
{
val scalaTest = "org.scalatest" %% "scalatest" % "3.0.1" % "test"
val scalactic = "org.scalactic" %% "scalactic" % "3.0.1"
val scalaTags = "com.lihaoyi" %% "scalatags" % "0.6.2"
}
lazy val proto = (project in file("modules/proto"))
.settings(generalSettings: _*)
.settings(
PB.targets in Compile := Seq(
scalapb.gen() -> (sourceManaged in Compile).value
),
// If you need scalapb/scalapb.proto or anything from google/protobuf/*.proto
libraryDependencies ++= Seq(
"com.trueaccord.scalapb" %% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion % "protobuf",
"com.trueaccord.scalapb" %%% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion,
"com.trueaccord.scalapb" %%% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion % "protobuf"
)
)
lazy val play = (project in file("modules/play"))
.enablePlugins(PlayScala)
.settings(generalSettings: _*)
.settings(
name := "play",
libraryDependencies ++= Seq(
CrossDependencies.scalaTest,
CrossDependencies.scalactic,
CrossDependencies.scalaTags,
"com.typesafe.play" %% "play-json" % "2.6.0-M1"),
scalaJSProjects := Seq(client),
pipelineStages in Assets := Seq(scalaJSPipeline),
compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value
)
.aggregate(slick)
.dependsOn(slick)
.aggregate(flyway)
.dependsOn(flyway)
.aggregate(proto)
.dependsOn(proto)
lazy val client = (project in file("modules/client"))
.enablePlugins(ScalaJSPlugin, ScalaJSWeb)
.settings(generalSettings: _*)
.settings(
name := "client",
libraryDependencies += CrossDependencies.scalaTags,
persistLauncher := true
)
.aggregate(proto)
.dependsOn(proto)
// Loads the jvm project at sbt startup
onLoad in Global := (Command.process("project play", _: State)) compose (onLoad in Global).value
fork in run := true
and this is the plugins.sbt:
// Scala.JS
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.14")
addSbtPlugin("com.vmunier" % "sbt-web-scalajs" % "1.0.2")
// Play
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.0-SNAPSHOT")
// Proto
addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.3" exclude ("com.trueaccord.scalapb", "protoc-bridge_2.10"))
libraryDependencies += "com.trueaccord.scalapb" %% "compilerplugin-shaded" % "0.5.47"
This is one proto file:
syntax = "proto3";
package tld.awesomeness.proto;
message Test {
int32 id = 1;
string email = 2;
}
After compilation I get Test.class
Now in the client I try to:
private def doSend(ws: WebSocket): Unit =
{
val msg = Test().withId(1337)
val a: ArrayBuffer = new ArrayBuffer(msg.toByteArray.length)
msg.toByteArray
ws.send(a)
}
(The websocket itself worked all just fine when I sent strings through it!)
Now I get this huge stacktrace:
[info] Fast optimizing /home/sorona/awesomeness/modules/client/target/scala-2.12/client-fastopt.js
[error] Referring to non-existent class tld.awesomeness.proto.Test.Test$
[error] called from tld.awesomeness.ScalaJSTest$.doSend(org.scalajs.dom.raw.WebSocket)scala.Unit
[error] called from tld.awesomeness.ScalaJSTest$.tld$awesomeness$ScalaJSTest$$$anonfun$call$1(org.scalajs.dom.raw.Event,org.scalajs.dom.raw.WebSocket)org.scalajs.dom.raw.Event
[error] called from tld.awesomeness.ScalaJSTest$.call()scala.Unit
[error] called from tld.awesomeness.Main$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] tld.awesomeness.ScalaJSTest$
[error] tld.awesomeness.Main$
[error] Referring to non-existent class tld.awesomeness.proto.Test.Test
[error] called from tld.awesomeness.ScalaJSTest$.doSend(org.scalajs.dom.raw.WebSocket)scala.Unit
[error] called from tld.awesomeness.ScalaJSTest$.tld$awesomeness$ScalaJSTest$$$anonfun$call$1(org.scalajs.dom.raw.Event,org.scalajs.dom.raw.WebSocket)org.scalajs.dom.raw.Event
[error] called from tld.awesomeness.ScalaJSTest$.call()scala.Unit
[error] called from tld.awesomeness.Main$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] tld.awesomeness.ScalaJSTest$
[error] tld.awesomeness.Main$
[error] Referring to non-existent method tld.awesomeness.proto.Test.Test.toByteArray()[scala.Byte
[error] called from tld.awesomeness.ScalaJSTest$.doSend(org.scalajs.dom.raw.WebSocket)scala.Unit
[error] called from tld.awesomeness.ScalaJSTest$.tld$awesomeness$ScalaJSTest$$$anonfun$call$1(org.scalajs.dom.raw.Event,org.scalajs.dom.raw.WebSocket)org.scalajs.dom.raw.Event
[error] called from tld.awesomeness.ScalaJSTest$.call()scala.Unit
[error] called from tld.awesomeness.Main$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] tld.awesomeness.ScalaJSTest$
[error] tld.awesomeness.Main$
[error] Referring to non-existent method tld.awesomeness.proto.Test.Test.withId(scala.Int)tld.awesomeness.proto.Test.Test
[error] called from tld.awesomeness.ScalaJSTest$.doSend(org.scalajs.dom.raw.WebSocket)scala.Unit
[error] called from tld.awesomeness.ScalaJSTest$.tld$awesomeness$ScalaJSTest$$$anonfun$call$1(org.scalajs.dom.raw.Event,org.scalajs.dom.raw.WebSocket)org.scalajs.dom.raw.Event
[error] called from tld.awesomeness.ScalaJSTest$.call()scala.Unit
[error] called from tld.awesomeness.Main$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] tld.awesomeness.ScalaJSTest$
[error] tld.awesomeness.Main$
[error] Referring to non-existent method tld.awesomeness.proto.Test.Test$.apply$default$2()java.lang.String
[error] called from tld.awesomeness.ScalaJSTest$.doSend(org.scalajs.dom.raw.WebSocket)scala.Unit
[error] called from tld.awesomeness.ScalaJSTest$.tld$awesomeness$ScalaJSTest$$$anonfun$call$1(org.scalajs.dom.raw.Event,org.scalajs.dom.raw.WebSocket)org.scalajs.dom.raw.Event
[error] called from tld.awesomeness.ScalaJSTest$.call()scala.Unit
[error] called from tld.awesomeness.Main$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] tld.awesomeness.ScalaJSTest$
[error] tld.awesomeness.Main$
[error] Referring to non-existent method tld.awesomeness.proto.Test.Test$.apply$default$1()scala.Int
[error] called from tld.awesomeness.ScalaJSTest$.doSend(org.scalajs.dom.raw.WebSocket)scala.Unit
[error] called from tld.awesomeness.ScalaJSTest$.tld$awesomeness$ScalaJSTest$$$anonfun$call$1(org.scalajs.dom.raw.Event,org.scalajs.dom.raw.WebSocket)org.scalajs.dom.raw.Event
[error] called from tld.awesomeness.ScalaJSTest$.call()scala.Unit
[error] called from tld.awesomeness.Main$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] tld.awesomeness.ScalaJSTest$
[error] tld.awesomeness.Main$
[error] Referring to non-existent method tld.awesomeness.proto.Test.Test.<init>(scala.Int,java.lang.String)
[error] called from tld.awesomeness.ScalaJSTest$.doSend(org.scalajs.dom.raw.WebSocket)scala.Unit
[error] called from tld.awesomeness.ScalaJSTest$.tld$awesomeness$ScalaJSTest$$$anonfun$call$1(org.scalajs.dom.raw.Event,org.scalajs.dom.raw.WebSocket)org.scalajs.dom.raw.Event
[error] called from tld.awesomeness.ScalaJSTest$.call()scala.Unit
[error] called from tld.awesomeness.Main$.main()scala.Unit
[error] called from scala.scalajs.js.JSApp.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.$$js$exported$meth$main()java.lang.Object
[error] called from tld.awesomeness.Main$.main
[error] exported to JavaScript with #JSExport
[error] involving instantiated classes:
[error] tld.awesomeness.ScalaJSTest$
[error] tld.awesomeness.Main$
java.lang.RuntimeException: There were linking errors
at scala.sys.package$.error(package.scala:27)
at org.scalajs.core.tools.linker.frontend.BaseLinker.linkInternal(BaseLinker.scala:133)
at org.scalajs.core.tools.linker.frontend.BaseLinker.linkInternal(BaseLinker.scala:86)
at org.scalajs.core.tools.linker.frontend.LinkerFrontend$$anonfun$4.apply(LinkerFrontend.scala:54)
at org.scalajs.core.tools.linker.frontend.LinkerFrontend$$anonfun$4.apply(LinkerFrontend.scala:54)
at org.scalajs.core.tools.logging.Logger$class.time(Logger.scala:28)
at org.scalajs.sbtplugin.Loggers$SbtLoggerWrapper.time(Loggers.scala:7)
at org.scalajs.core.tools.linker.frontend.LinkerFrontend.link(LinkerFrontend.scala:53)
at org.scalajs.core.tools.linker.Linker$$anonfun$link$1.apply$mcV$sp(Linker.scala:50)
at org.scalajs.core.tools.linker.Linker$$anonfun$link$1.apply(Linker.scala:49)
at org.scalajs.core.tools.linker.Linker$$anonfun$link$1.apply(Linker.scala:49)
at org.scalajs.core.tools.linker.Linker.guard(Linker.scala:67)
at org.scalajs.core.tools.linker.Linker.link(Linker.scala:49)
at org.scalajs.core.tools.linker.ClearableLinker$$anonfun$link$1.apply(ClearableLinker.scala:51)
at org.scalajs.core.tools.linker.ClearableLinker$$anonfun$link$1.apply(ClearableLinker.scala:51)
at org.scalajs.core.tools.linker.ClearableLinker.linkerOp(ClearableLinker.scala:62)
at org.scalajs.core.tools.linker.ClearableLinker.link(ClearableLinker.scala:51)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$org$scalajs$sbtplugin$ScalaJSPluginInternal$$scalaJSStageSettings$4$$anonfun$apply$6$$anonfun$apply$7.apply(ScalaJSPluginInternal.scala:251)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$org$scalajs$sbtplugin$ScalaJSPluginInternal$$scalaJSStageSettings$4$$anonfun$apply$6$$anonfun$apply$7.apply(ScalaJSPluginInternal.scala:239)
at sbt.FileFunction$$anonfun$cached$1.apply(Tracked.scala:253)
at sbt.FileFunction$$anonfun$cached$1.apply(Tracked.scala:253)
at sbt.FileFunction$$anonfun$cached$2$$anonfun$apply$3$$anonfun$apply$4.apply(Tracked.scala:267)
at sbt.FileFunction$$anonfun$cached$2$$anonfun$apply$3$$anonfun$apply$4.apply(Tracked.scala:263)
at sbt.Difference.apply(Tracked.scala:224)
at sbt.Difference.apply(Tracked.scala:206)
at sbt.FileFunction$$anonfun$cached$2$$anonfun$apply$3.apply(Tracked.scala:263)
at sbt.FileFunction$$anonfun$cached$2$$anonfun$apply$3.apply(Tracked.scala:262)
at sbt.Difference.apply(Tracked.scala:224)
at sbt.Difference.apply(Tracked.scala:200)
at sbt.FileFunction$$anonfun$cached$2.apply(Tracked.scala:262)
at sbt.FileFunction$$anonfun$cached$2.apply(Tracked.scala:260)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$org$scalajs$sbtplugin$ScalaJSPluginInternal$$scalaJSStageSettings$4$$anonfun$apply$6.apply(ScalaJSPluginInternal.scala:256)
at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$org$scalajs$sbtplugin$ScalaJSPluginInternal$$scalaJSStageSettings$4$$anonfun$apply$6.apply(ScalaJSPluginInternal.scala:237)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[error] (client/compile:fastOptJS) There were linking errors
My ide finds everything but obviously I am doing something wrong. I already had a look at https://github.com/thesamet/scalapbjs-test but to no avail.
Problem appears with that line val msg = Test().withId(1337)
edit: after comment I changed build.sbt:
lazy val proto = (crossProject in file("modules/proto"))
.settings(generalSettings: _*)
.settings(
PB.targets in Compile := Seq(
scalapb.gen() -> (sourceManaged in Compile).value
)).
jvmSettings(
libraryDependencies += "com.trueaccord.scalapb" %% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion % "protobuf",
PB.targets in Compile := Seq(
scalapb.gen() -> (sourceManaged in Compile).value
)
).
jsSettings(
libraryDependencies ++= Seq(
"com.trueaccord.scalapb" %%% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion,
"com.trueaccord.scalapb" %%% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion % "protobuf"
),
PB.targets in Compile := Seq(
scalapb.gen() -> (sourceManaged in Compile).value
)
)
lazy val protoJs = proto.js
lazy val protoJVM = proto.jvm
lazy val play = (project in file("modules/play"))
.enablePlugins(PlayScala)
.settings(generalSettings: _*)
.settings(
name := "play",
libraryDependencies ++= Seq(
CrossDependencies.scalaTest,
CrossDependencies.scalactic,
CrossDependencies.scalaTags,
"com.typesafe.play" %% "play-json" % "2.6.0-M1"),
scalaJSProjects := Seq(client),
pipelineStages in Assets := Seq(scalaJSPipeline),
compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value
)
.aggregate(slick)
.dependsOn(slick)
.aggregate(flyway)
.dependsOn(flyway)
.aggregate(protoJVM)
.dependsOn(protoJVM)
lazy val client = (project in file("modules/client"))
.enablePlugins(ScalaJSPlugin, ScalaJSWeb)
.settings(generalSettings: _*)
.settings(
name := "client",
libraryDependencies += CrossDependencies.scalaTags,
persistLauncher := true
)
.aggregate(protoJs)
.dependsOn(protoJs)
now now neither play nor client can resolve the proto-class :(
(Also I am aware of the redundant PB.targets in Compile..., I just thought that sharing might not work there, so I added it to both distinct settings again)
With pure CrossProject you need to specify the actual path ScalaPB should look for proto files (the value it guesses is wrong). Here is a minimal example:
lazy val proto = (crossProject.crossType(CrossType.Pure) in file("proto"))
.settings(
PB.targets in Compile := Seq(
scalapb.gen() -> (sourceManaged in Compile).value
),
// The trick is in this line:
PB.protoSources in Compile := Seq(file("proto/src/main/protobuf")),
libraryDependencies ++= Seq(
"com.trueaccord.scalapb" %%% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion,
"com.trueaccord.scalapb" %%% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion % "protobuf"
)
)

Can't Run `test` in Scala Test with SBT

src/main/scala/Testing.scala
package common
object Add1Method {
def main(args: Array[String]) = 100+2
}
project/build.sbt
name := "Foo"
version := "1.0"
scalaVersion := "2.10.2"
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "1.9.1" % "test"
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
resolvers += "Sonatype Releases" at "http://oss.sonatype.org/content/repositories/releases"
src/test/scala/Test.scala
package test
import common.Testing
import org.scalatest._
class Test extends FlatSpec with Matchers {
"running main" should "return 102" in {
val result = Add1Method.main(Array("asdf"))
assert(result == 102)
}
}
But, when I run test from SBT, the following 4 compile-time errors:
[error] Test.scala:4: object scalatest is not a member of package org
[error] import org.scalatest._
[error] ^
[error] Test.scala:6: not found: type FlatSpec
[error] class Test extends FlatSpec with Matchers {
[error] ^
[error] Test.scala:6: not found: type Matchers
[error] class Test extends FlatSpec with Matchers {
[error] ^
[error] Test.scala:8: value should is not a member of String
[error] "running main" should "return 102" in {
[error] ^
[error] four errors found
Note that I tried the suggested answer in SBT not finding scalatest for scala 2.10.1 without success.
The ScalaTest example uses the same imports - http://www.scalatest.org/quick_start.
I think the problem is that your build.sbt is in the wrong place. It should not be in project/ but in the root directory, next to the src directory.
See Directories in the sbt documentation for more info.

sbt error when forking is enabled

Sbt produce an error when there is this line:
fork in run := true
in this build.scala file
The surrounding build.scala content
lazy val scalafxDemos = Project(
id = "scalafx-demos",
base = file("scalafx-demos"),
settings = scalafxSettings ++ Seq(
libraryDependencies ++= Seq(
scalatest % "test",
junit % "test"),
unmanagedListing,
description := "The ScalaFX demonstrations",
fork in run := true,
fork in Test := true,
parallelExecution in Test := false,
// print junit-style XML for CI
testOptions in Test <+= (target in Test) map {
t => Tests.Argument(TestFrameworks.ScalaTest, "-u", "%s" format (t / "junitxmldir"))
},
The error produced:
[error] /Users/hanxue/Github/scalafx/project/build.scala:113: overloaded method value in with alternatives:
[error] (scope: sbt.Scope)sbt.SettingKey[Boolean] <and>
[error] (c: sbt.ConfigKey)sbt.SettingKey[Boolean] <and>
[error] (t: sbt.Scoped)sbt.SettingKey[Boolean] <and>
[error] (p: sbt.Reference)sbt.SettingKey[Boolean]
[error] cannot be applied to (run.type)
[error] fork in run := true,
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
I can avoid the error by changing the line to fork := true, though that does satisfy the intent of forking only in run and Test. How can I fix this without forcing everything else to be forked?
That probably means run is coming from somewhere else. You might try an explicit Keys.run to see if this is the case.