Can't compile 2.2 to 2.3 Migration - scala

I have been fighting with this for the past few hours and I haven't made any headway at all. It seems no matter what I do, I keep getting the same error.
java.lang.NoClassDefFoundError: play/Project$
My build.sbt
name := "appname"
version := "1.0-SNAPSHOT"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
filters,
"org.postgresql" % "postgresql" % "9.3-1100-jdbc4",
"org.mindrot" % "jbcrypt" % "0.3m",
"org.webjars" %% "webjars-play" % "2.3.0-2",
"org.webjars" % "foundation" % "5.3.0",
"org.scalaj" %% "scalaj-http" % "0.3.16"
)
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.10.4"
I have also tried this build.sbt
object ApplicationBuild extends Build {
val appName = "appname"
val appVersion = "1.0-SNAPSHOT"
val appDependencies ++= Seq(
jdbc,
anorm,
cache,
filters,
"org.postgresql" % "postgresql" % "9.3-1100-jdbc4",
"org.mindrot" % "jbcrypt" % "0.3m",
"org.webjars" %% "webjars-play" % "2.3.0-2",
"org.webjars" % "foundation" % "5.3.0",
"org.scalaj" %% "scalaj-http" % "0.3.16"
)
val main = Project(appName, file(".")).enablePlugins(play.PlayScala).settings(
scalaVersion := "2.10.4",
version := appVersion,
libraryDependencies ++= appDependencies
)
}
As well as different tweaks and modifications. Always the same error. The build.properties is set to sbt.version=0.13.5
plugins.sbt
logLevel := Level.Debug
// 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.3.4")
After running Patrick Mahoney's suggestion and making sure I removed the import.
Errors:
[error] java.lang.NoClassDefFoundError: play/Project$
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q
me#me-desktop:~/Projects/appname$ sbt --version
sbt launcher version 0.13.6
me#me-desktop:~/Projects/appname$ find . | grep -r "play.Project"
me#me-desktop:~/Projects/appname$ find . | grep -r "play/Project"

Try cleaning your build project compiled outputs:
rm -rf project/target
or
$> sbt "reload plugins" clean
(in addition to applying James' answer)

Thanks to James and Patrick, but I found the problem. The problem was in the activator-sbt-echo-play-shim.sbt file in the /project directory.
It contained the following:
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "0.1.1.3")
I created a second blank 2.3.4 app using Activator and it's activator-sbt-echo-play-shim.sbt listed:
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5")
So I updated the one in my project to 1.5 and deleted the idea and eclipse .sbts for good measure and the app was finally able to compile. It auotmatically updated the above to:
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.2")
Now I have other, more expected, issues I need to work out (like anorm). But I'm now able to compile it and get those errors to start working them out. I did not think these files were part of the activator/sbt compile, but I guess they were. I thought they were for debugging. But they made the difference and the changes above worked.
Thanks again to everyone for their help.

Make sure you've updated project/build.properties to have sbt version 0.13.5. Then, remove import play.Project._, it's not needed. That should work.

Related

Manage dependencies with sbt & IntelliJ IDEA

I'm working on a back-end project using for the first time Scala and the Play Framework with IntelliJ IDEA.
I've been reading a lot of documentation and topics:
SBT Library dependencies doc
IntelliJ support post
Another post from stackoverflow
I can't understand how to import dependencies.
When I try to append a new dependency, IntelliJ underlines it and shows either "Unknown artifact. Not resolved or indexed" or a log shows up and says "SBT unknown import".
Every dependency I add is from the Maven Repository.
Here is the build.sbt file:
name := "server"
version := "1.0"
lazy val `server` = (project in file(".")).enablePlugins(PlayScala)
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
resolvers += "Akka Snapshot Repository" at "http://repo.akka.io/snapshots/"
resolvers := ("Atlassian Releases" at "https://maven.atlassian.com/public/") +: resolvers.value
scalaVersion := "2.12.2"
libraryDependencies ++= Seq(
jdbc,
ehcache,
ws,
specs2 % Test,
guice,
"org.mongodb.scala" %% "mongo-scala-driver" % "2.1.0",
"com.mohiva" %% "play-silhouette" % "5.0.2",
"com.mohiva" %% "play-silhouette-password-bcrypt" % "5.0.2",
"com.mohiva" %% "play-silhouette-crypto-jca" % "5.0.2",
"com.mohiva" %% "play-silhouette-persistence" % "5.0.2",
"com.mohiva" %% "play-silhouette-testkit" % "5.0.2" % "test"
)
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
These dependencies were specified using a shorthand that is defined by the Play plugin:
jdbc,
ehcache,
ws,
specs2 % Test,
guice
So for them to work, be sure to include a line like the following in an .sbt file in the project directory:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.10")
That should fix your problem.
Bonus tip: No need for the following lines, and because each additional resolver slows down SBT, you should delete them:
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
resolvers += "Akka Snapshot Repository" at "http://repo.akka.io/snapshots/"
resolvers := ("Atlassian Releases" at "https://maven.atlassian.com/public/") +: resolvers.value

How to attach sources to scala sbt project at Intellij Idea?

I am new at scala. And for start I want to use Intellij 13.1.5 IDE.
However IDE can't attach sources. Here is how it looks for AnyVal:
Search at internet can't find any source.
I tried Attach sources and attach unpacked scala archive. It doesn't work either.
UPDATE:
Here is sbt configuration:
name := "scalatest-selenium"
version := "1.0"
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
"net.sourceforge.htmlunit" % "htmlunit" % "2.14",
"org.seleniumhq.selenium" % "selenium-java" % "2.42.2",
"org.scalacheck" % "scalacheck_2.10" % "1.11.4" % "test",
"org.scalatest" % "scalatest_2.11" % "2.2.0" % "test"
)
testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-u", "target/test-reports")
How to solve this trouble?
I get rid of this trouble at the following way:
removed the .sbt directory in your Home Folder.
When you run sbt again, the new folder is created in the correct format and the error goes away.

object typesafe is not a member of package

I am currently trying to build and deploy a simple scala application on heroku. I am following the tutorial on the heroku website for Scala: https://devcenter.heroku.com/articles/getting-started-with-scala
However I keep getting the following error when I execute sbt clean compile stage:
My build.sbt file is as follows:
import com.typesafe.startscript.StartScriptPlugin
seq(StartScriptPlugin.startScriptForClassesSettings: _*)
name := "hello"
version := "1.0"
scalaVersion := "2.9.2"
resolvers += "twitter-repo" at "http://maven.twttr.com"
libraryDependencies ++= Seq("com.twitter" % "finagle-core" % "1.9.0", "com.twitter" % "finagle-http" % "1.9.0")
I have a project/build.sbt file as well as follows:
resolvers += "twitter-repo" at "http://maven.twttr.com"
libraryDependencies ++= Seq("com.twitter" % "finagle-core" % "1.9.0", "com.twitter" % "finagle-http" % "1.9.0")
My project/build.properties file is as follows:
sbt.version=0.12.0
Anyone know what I am doing wrong?, help greatly appreciated
You got project/build.sbt wrong: it should be
resolvers += Classpaths.typesafeResolver
addSbtPlugin("com.typesafe.startscript" % "xsbt-start-script-plugin" % "0.5.3")
according to the tutorial. More generally, try reading SBT documentation.

SBT 0.7.7 incremental recompilation doesnt work anymore

I'm using sbt 0.7.7 on ubuntu 12.10 to build a Lift app (Lift 2.4/Java 1.6/ Scala 2.7.7)
When I modify a source file, the sbt compiler recompiles all (even independent) files.
A debug output of "compile" shows:
[debug] External /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/jce.jar not on classpath.
[debug] External dependency /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/jce.jar not found.
I'm using ~compile and the file is available in the correct path.
Can anybody help me?
** Solution **
Thanks for your help.
It looks like sbt 0.7.7 can't handle symlinks correctly.
I removed the symlink and replaced it by a copy of the original file. This solved the problem.
But we're also updating to sbt 12.3 as soon as possible.
I have this file on my ubuntu 13.04
are you sure they're independent? Is it checkable in some way?
what command do you use for compilation? ~ compile ?
I'd suggest to move from the old SBT, old Lift and old Scala anyway. They're far-far away old, new versions have many improvements in performance and allowed techniques. And in the Scala environment it's common to evolutionize quickly, reducing the maintenance period. Check out the most recent official template: https://github.com/lift/lift_25_sbt/
SBT 0.7.7 is severely deprecated. Unless there is any specific reason for which you have to use that version, a 0.12.3 upgrade will make things much easier.
Most frameworks do not legacy support that version of SBT.
Make sure Java is there
Don't use the open source version of the JDK, it is known to cause hassle with Scala at times.
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
Sample config
name := "YourApp"
version := "0.1-SNAPSHOT"
scalaVersion := "2.10.0"
seq(com.github.siasia.WebPlugin.webSettings :_*)
seq(jrebelSettings: _*)
jrebel.webLinks <++= webappResources in Compile
resolvers ++= Seq(
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
"Sonatype releases" at "https://oss.sonatype.org/content/repositories/releases"
)
libraryDependencies ++= {
val liftVersion = "2.5-RC6"
Seq(
"commons-lang" % "commons-lang" % "2.6",
"net.liftweb" %% "lift-webkit" % liftVersion % "compile",
"net.liftweb" %% "lift-mongodb-record" % liftVersion % "compile",
"org.mongodb" %% "casbah" % "2.5.0" % "compile",
"org.eclipse.jetty" % "jetty-webapp" % "8.1.7.v20120910" % "container,compile",
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container,compile" artifacts Artifact("javax.servlet", "jar", "jar"),
"org.specs2" %% "specs2" % "1.12.3" % "test",
"ch.qos.logback" % "logback-classic" % "1.0.7" % "compile"
)
}
classpathTypes ~= (_ + "orbit")
port in container.Configuration := 9100
EclipseKeys.withSource := true

Need help getting sbt 0.10 to choose a local copy of scala 2.9.1.final on Ubuntu

What I have so far:
.bashrc
2 PATH=/opt/scala-2.9.1.final/bin:$PATH
3 PATH=/opt/sbt:$PATH
So my scala-2.9.1.final version is in the /opt folder. The same goes with sbt 0.10.
I'm trying to get it to pick my 2.9.1.final instead of 2.8 whatever. I've tried looking.
What i've done so far is putting symbolic links in projectname/boot/ directory.
ln -s /opt/scala-2.9.1.final scala-2.9.1.final
But it doesn't seem to work? I've also tried this build.sbt (https://github.com/VonC/xsbt-template/blob/master/build.sbt) and change the version to 2.9.1.final.
How do I get sbt>console to use 2.9.1.final? And how does it build using 2.9.1.final?
This is what I get when I type sbt:
user#acomputer:~/project/sbt$ sbt
[info] Set current project to default-295917 (in build file:/home/user/project/sbt/)
>
Thank you for your time.
I'm not experienced sbt user and may only suggest. Seems sbt 0.10.x use scala 2.8.1 itself, so I think sbt console is working by default with this version.
But you can build project with targetting on 2.9.1 by specify scala version in you build.sbt file: `scalaVersion := "2.9.1"' (see https://github.com/harrah/xsbt/wiki/Setup "ConfigureBuild")
And also you can switch scala version used by sbt console by typing "++ 2.9.1" in sbt prompt. (see https://github.com/harrah/xsbt/wiki/Running)
Here's an example of an build.sbt in one of my projects.
organization := "com.andyczerwonka"
name := "esi.intelligence"
version := "0.1"
scalaVersion := "2.9.1"
retrieveManaged := false
logLevel := Level.Info
jettyScanDirs := Nil
seq(webSettings :_*)
temporaryWarPath <<= (sourceDirectory in Compile)(_ / "webapp")
libraryDependencies ++= {
val liftVersion = "2.4-M4"
Seq(
"net.liftweb" %% "lift-webkit" % liftVersion % "compile->default",
"net.liftweb" %% "lift-mapper" % liftVersion % "compile",
"org.eclipse.jetty" % "jetty-webapp" % "7.3.0.v20110203" % "provided,jetty",
"junit" % "junit" % "4.8" % "test",
"ch.qos.logback" % "logback-classic" % "0.9.26",
"org.specs2" %% "specs2" % "1.6.1" % "test",
"net.databinder" %% "dispatch-http" % "0.8.5",
"com.h2database" % "h2" % "1.2.138"
)
}
Notice the 4th line. This tells sbt that I want to use 2.9.1. sbt will bring it down for me and use it.