Playframework samples didn't build - scala

On Macos Maverics, I have following issue:
I cloned Playframework repository and wanted to build the samples. Unfortunately it doesn't work. I have playframework on my path, play-2.2.3.
I tried to import it from Intellij IDEA but the same error.
localhost:helloworld radimpavlicek$ play
[info] Loading project definition from /Users/radimpavlicek/Documents/playframework/samples/scala/helloworld/project
/Users/radimpavlicek/Documents/playframework/samples/scala/helloworld/build.sbt:5: error: not found: value PlayScala
lazy val root = (project in file(".")).enablePlugins(PlayScala)
`` ^
[error] sbt.compiler.EvalException: Type error in expression
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?

I just had the same problem in Ubuntu 14.04 trying to build the zentask sample app. I eliminated the offending line in the build.sbt and added play.Project.playScalaSettings to the end and was able to compile and run from the Play console. This is my current zentask build.sbt (empty lines are needed):
name := "zentask"
version := "1.0"
libraryDependencies ++= Seq(jdbc, anorm)
scalaVersion := Option(System.getProperty("scala.version")).getOrElse("2.10.4")
play.Project.playScalaSettings

The application build has changed from Play 2.2.x to 2.3.x, and your build.sbt appears to be in 2.3 format. If you've checked out the helloworld project from Github, make sure you're on the 2.2.x branch or otherwise upgrade Play to 2.3.0-RC1 (the latest as of this writing.) In 2.2, the build.sbt for the helloworld sample consists of this in its entirety:
import play.Project._
name := "helloworld"
version := "1.0"
playScalaSettings

enablePlugins isn't available in sbt.Project until sbt 0.13.5.
You can update your sbt version following this link http://www.scala-sbt.org/download.html and instead of using install, use update/upgrade(depends on you package manager)

Related

sbt android won't run android:package on example project multiproject-same-dependencies because of libraryProject errors

I have checked out the sbt-android project source at commit de0b517 and then tried to run the android:package task in the example project multiproject-same-dependencies. I get these errors:
[error] (b/android:apkbuild) This project cannot build APK, it has set 'libraryProject in Android := true'
[error] (c/android:apkbuild) This project cannot build APK, it has set 'libraryProject in Android := true'
[error] (d/android:apkbuild) This project cannot build APK, it has set 'libraryProject in Android := true'
I have been following the layout in this project to try and build my own android project with two submodules and am hitting the same error there. One submodule is itself an android library (which I get an error for), and the other is just some java sources with no android dependencies.
I don't know if this is relevant, but on my system, the example project didn't build out of the box. I made these changes:
add project/build.properties setting sbt.version=0.13.9
add project/plugins.sbt setting addSbtPlugin("org.scala-android" % "sbt-android" % "1.6.1")
I realize that these changes can be avoided by using a global installation in ~/.sbt, but I am trying to emulate my actual project's settings which explicitly import these in order to make it more self-contained and portable by minimizing environmental dependencies.
This is the build.sbt for my personal project if it helps:
val androidSettings = Seq(platformTarget := "android-15", dexMulti := true)
javacOptions in Compile ++= Seq("-source", "1.7", "-target", "1.7")
lazy val actionbarsherlock =
project
.settings(exportJars := true)
.settings(androidBuildAar)
.settings(androidSettings: _*)
lazy val util =
project
.settings(exportJars := true)
lazy val androminion =
project
.dependsOn(util)
.androidBuildWith(actionbarsherlock)
.settings(androidSettings: _*)
.settings(exportJars := true)
libraryDependencies in actionbarsherlock ++= Seq(
"com.android.support" % "support-v4" % "18.0.0"
)
Is this the idiomatic way to define an android project which depends on another android project and a non-android project?
Regarding my java installation:
$ java -version
java version "1.7.0_60"
Thanks!
You would run
androminion/android:package

Can't find Spark libraries when using Eclipse

I used to code Scala within the terminal, but now I'm trying
with the ScalaIDE for Eclipse.
However, I've got one big problem:
error: not found: value sc
I've tried to add those libraries
import org.apache.spark.SparkContext
import org.apache.spark.SparkConf
But then it displays:
object apache is not a member of package org
So I don't know what to do....
In my IntelliJ project my build.sbt is pretty empty:
name := "test"
version := "1.0"
scalaVersion := "2.11.7"
is it a sbt project? make sure you have eclipse plugin for scala/sbt, and import it as a sbt project.
also, add the dependency on the build.sbt
nevertheless, I prefer Intellij :)

Using a custom sbt plugin

I've created a new scala project and written an AutoPlugin underneath it in a src/main/scala/com/company/plugin directory and a corresponding namespace. The plugin code is a cut and paste of HelloPlugin3 from [1], however I have changed the names.
Then, in a second sbt project I've updated the project/plugins.sbt file to include my new Hello World plugin. This second project has other 'business code' in. When I run sbt in that second project, the plugin is resolved and I've tested that by deleting the jar from underneath the ~/.ivy/local/... and then reloading the project and witnessing sbt complain that it can't find the plugin. When I publishLocal my plugin project again, that error goes away.
So I'm happy that the plugin is resolved and the jar file is not empty because I have checked its contents.
However, when I do an sbt> about my custom plugin isn't listed and the command I was expecting to be available isn't. ("[error] Not a valid command: hello"). But the other plugin I list in plugins.sbt (io.spray sbt-revolver) does appear in the output.
Both the plugin project and the second project have scalaVersion := "2.10.3" specified in their build.sbt files.
I'm using sbt 0.13.6. Interestingly, and perhaps related, is the sbt command plugins is not apparently valid in this project either, although it works just fine in the plugin project.
What extra step am I missing to make the command available to my second project? How do I check to see if I've got some particularly messed up sbt config happening?
For convenience, the plugin code is below, but as mentioned, it's a copy from the link underneath it.
package com.company.plugin
import sbt._
import Keys._
object HelloPlugin extends AutoPlugin {
object autoImport {
val greeting = settingKey[String]("greeting")
}
import autoImport._
override def trigger = allRequirements
override lazy val buildSettings = Seq(
greeting := "Hi",
commands += helloCommand)
lazy val helloCommand =
Command.command("hello") { (state: State) =>
println("fred")
state
}
}
Edit:
The build.sbt for the plugin project as as follows;
sbtPlugin := true
scalaVersion := "2.10.3"
organization := "com.company"
name := "name"
version := "0.0.1-SNAPSHOT"
The only other file I've created in this project is the .scala file for the plugin itself.
[1] http://www.scala-sbt.org/release/docs/Plugins.html
The problem ended up being with the project/build.properties of the project trying to use the plugin. This file set the sbt version to 0.13.1, which for some reason cases both my plugin and the sbt plugins command to not work.
Changing the value to 0.13.6 made all the problems go away.

Play 2.3 run error

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

Migration from Play framework 2.0.4 to 2.2.0

I have an application build on top of the Play framework 2.0.4. I would like to migrate it to the newest version (which is currently 2.2.0).
So I've updated my local Play framework installation, all build files accordingly:
build.properties:
sbt.version=0.13.0
Build.scala:
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "demagog"
val appVersion = "1.0.0"
val appDependencies = Seq(
javaCore,
"com.google.code.morphia" % "morphia" % "0.99",
"com.google.code.morphia" % "morphia-logging-slf4j" % "0.99",
"net.tanesha.recaptcha4j" % "recaptcha4j" % "0.0.7"
)
val main = play.Project(appName, appVersion, appDependencies).settings(
// Add your own project settings here
resolvers += "Morphia repository" at "http://morphia.googlecode.com/svn/mavenrepo/"
)
}
plugins.sbt:
// Comment to get more information during initialization
logLevel := Level.Warn
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")
Then I tried to "eclipsify" my project. So I run exactly these two commands:
play clean-all
play eclipse
and I get lots of errors like:
[error] ..\Api.java:11: error: package org.codehaus.jackson does not exist
import org.codehaus.jackson.JsonNode;
which is expected due to the fact I found in the Migration guide:
We have upgraded Jackson to version 2 which means that the package name is now com.fasterxml.jackson.core instead of org.codehaus.jackson.
But at the end of "play eclipse" command I get this error:
[error] (compile:compile) javac returned nonzero exit code
[error] Could not create Eclipse project files:
[error] Error evaluating task 'dependencyClasspath': error
So the project is not "eclipsified" and I can't use it nor edit in my Eclipse IDE. This compiling on backgroung outside of the Eclipse IDE is really painfull and prevents me from productive using Play framework :-/
You can delete all source code files, generate the IDE files and then restore the source code from version control.
Sadly that is how the eclipse (and idea) plugin work, you will have to have a working project before you can re-export the project from SBT to eclipse. So you will just have to work through the compilation errors without the usual support from eclipse.