Play 2.3 run error - scala

I'm experiencing a problem when running latest play framework 2.3.
It compiles just fine, although when I do activator run this error happens:
java.lang.NoSuchMethodError: scala.Predef$.ArrowAssoc(Ljava/lang/Object;)Ljava/lang/Object;
Full error log
I explicitly tried scalaVersion in every build.sbt file and it is the same.
I tried several things like activator clean, full removal os sbt caches and local repo sbt stuff, updating dependencies to latest version but no success.
I have scala version defined.
My current dependencies are:
I tried with both %% and force _2.11 in the name of the dependency.
Dependency List
Other important files
build.sbt
Common.scala
Dependencies.scala
When I fully clean caches it downloads scala 2.10.4 for no reason:
in this download log it says the sbt need the old scala.
Any idea why is this?
Any ideas?

Firstly, it does not matter which version of Scala is used to generate your build. The build system can use version 2.10.4, and that does not prevent your code from using version 2.11.1.
To look at the issue with your scala version, you should consider that settings added directly in build.sbt are added to the root project, but not to other projects. You can see this with a minimal project such as:
$ cat build.sbt
scalaVersion := "2.11.1"
lazy val subproj = project in (file("subproj"))
Then the output of sbt looks like this:
> show scalaVersion
[info] subproj/*:scalaVersion
[info] 2.10.4
[info] sbttest/*:scalaVersion
[info] 2.11.1
So, how can this be fixed?
We can create a lazy val containing a Seq[Setting[_]], and add it to the sub-project definition with the settings() method.
Here's an example build.sbt which adds the same settings to all projects:
$ cat build.sbt
lazy val root = project.in(file("."))
.aggregate(subproj)
.dependsOn(subproj)
.settings(commonSettings: _*)
lazy val subproj = project.in(file("subproj"))
.settings(commonSettings: _*)
lazy val commonSettings = Seq(
scalaVersion := "2.11.1"
)
The _* is required because settings() is defined as requiring Setting[_]* rather than Seq[Setting[_]], so _* converts between the two types. See also: What does param: _* mean in Scala?
And the output from sbt is:
> show scalaVersion
[info] subproj/*:scalaVersion
[info] 2.11.1
[info] root/*:scalaVersion
[info] 2.11.1
This approach can easily be applied to your build.

You're defining your dependencies in the wrong way.
When using SBT, don't use:
"org.mydep" % "mydep_2.11" % "1.0.0"
Instead use:
"org.mydep" %% "mydep" % "1.0.0"
The %% operator automatically appends the current Scala version of the current build. If you use dependencies built against other Scala versions, you're going to be getting the weird errors.
Also make sure you explicitly specify your Scala version somewhere:
scalaVersion := "2.11.1"

The problem was related to some manually added jars that I discovered in the lib folder, that were causing issues with the dependencies of the project defined in the build.sbt.
The only way to find out was to generate a activator dist and look for similar dependencies with different versions since in the dependency graph there were no conflicts

Related

app-fastopt.js no longer properly added to resources after upgrading

I have been updating a project to scala 2.12, and one of my last remaining problems is that the fastOptJS task no longer seems to be providing the recompiled scala.js files to the new build.
I have the following lines in my build.sbt file:
lazy val appJVM = app.jvm
.settings(
(resources in Compile) ++= Seq(
(fastOptJS in (appJS, Compile)).value.data,
(packageJSDependencies in (appJS, Compile)).value
)
)
That used to do the task, but after updating to 2.12 my assets/app-fastopt.js file does not change despite running the fastOptJS task in every way I know how. The updated fastopt.js file DOES appear in the app/js/target/scala-2.12 subdirectory.
I am using version 0.6.25 of the scala.js plugin, on scala 2.12.6 and sbt 1.1.6
pacepalm
Please disregard. The browser was caching old versions.

After migrating library to scalajs, publish-local does not work

Following the hints of the post explaining the basics of migrating to scalajs and this page about cross-compilations, I decided to add cross compilation to my standalone dependency-free scala library by doing the following changes:
I added a file project/plugins.sbt with the content
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.16")
I added scalaVersion in ThisBuild := "2.11.8" in build.sbt because else just scalaVersion was using 2.10
I also added in the build.sbt the following content to ensure that I can keep the same directory structure, since I don't have any particular files for the JVM or for Javascript:
lazy val root = project.in(file(".")).
aggregate(fooJS, fooJVM).
settings(
publish := {},
publishLocal := {}
)
lazy val foo = crossProject.crossType(CrossType.Pure).in(file(".")).
settings(version := "0.1").
jvmSettings(
// Add JVM-specific settings here
).
jsSettings(
// Add JS-specific settings here
)
lazy val fooJVM = foo.jvm
lazy val fooJS = foo.js
But now, after I published the project locally using sbt publish-local the projects depending on this library do not work anymore, i.e. they don't see the classes that this library was offering and raise errors.
I looked into .ivy2/local/.../foo/0.1/jars and the JAR went from 1MB to 1KB, so the errors make sense.
However, how can I make sure the JVM jar file is compiled correctly?
Further informations
The jar time does not change anymore, it looks like there had been some miscompilation. I deleted the .ivy2 cache, but now sbt publish-local always finishes with success but does not regenerate the files.
Ok I found the solution myself.
I needed to remove the publishLocal := {} from the build, and now all the projects depending on my library work fine.

sbt console - set scala-version for all sub-projects

I have a multi-project build with scalaVersion := "2.11.8" for each module.
I want to run test and publish-local for Scala 2.12.0-RC1 without touching the build file. I thought the following would work:
$ sbt
> set scalaVersion in ThisBuild := "2.12.0-RC1"
> test
But that does not alter the Scala version used, sbt still compiles with Scala 2.11.8. This only works for single module builds (without project definitions).
How do I effectively override scalaVersion for all sub-modules from the sbt console?
Your attempt doesn't work because the setting for the module takes priority over the setting for ThisBuild; it would work if you used scalaVersion in ThisBuild in the build file instead of setting it separately for each module. I don't know if there is a way to do this with anything except scalaVersion, but:
As a final note, you can use ++ to temporarily switch the Scala version currently being used to build. should be either a version for Scala published to a repository, as in ++ 2.10.0 or the path to a Scala home directory, as in ++ /path/to/scala/home. See Command Line Reference for details.
> ++2.12.0-RC1
> test

Play Scala SBT not showing dependency in Reference Library in Eclipse

I created a new project using Play Scala and Eclipse. Added Squeryl dependency and see that it's been pulled during compile time. Confirmed it's present in .ivy2/cache/org.squeryl directory but eclipse project is not able to pull it up and causing compilation for import.
build.sbt
name := """registration"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
ws,
"org.squeryl" % "squeryl_2.10" % "0.9.6-RC2"
)
It looks like squeryl doesn't have a binary readily available for Scala 2.11 yet according to http://www.squeryl.org/getting-started.html
So if you want to use a pre-compiled version of this library you must change your scala version to 2.10.4.
All versions of squeryl available can be found at: http://mvnrepository.com/artifact/org.squeryl
I had a similar case using eclipse.
Select Project --> Clean to clean your workspace and build it again if you have not checked "Build Automatically".
If its still not visible please refresh the package explorer (or just the 'Referenced Library') with F5.

How does sbt choose which Scala version to use?

I have multiple projects in my sbt build. I'm trying to upgrade to Scala 2.10 from 2.9.1, so in my build.sbt file I put
scalaVersion := "2.10.0"
This seemed to work, because in my top-level project in sbt I get:
> scala-version
[info] 2.10.0
However, when I switch to one of the other projects:
> project web-client
[info] Set current project to web-client (in build file:/C:/Users/...
[web-client] $ scala-version
[info] 2.9.1
You see the version has now changed back to 2.9.1! How do I force the same Scala version to be used across all my projects?
I found out scoping the scalaVersion to ThisBuild will set it for all sub-projects. Details are here: http://www.scala-sbt.org/release/docs/Getting-Started/Multi-Project.html at the bottom, but here is what it says:
To set it only once, it is enough to write, in the main build.sbt file, the following line:
scalaVersion in ThisBuild := "2.10.0"
SBT has a default Scala version. You need to add the scalaVersion setting to all subprojects if you wish to change it. The most common way of doing that is having a "common settings" value that is added to all projects at the root level, through project/Build.scala.