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.
Related
Coming from Ruby on Rails, I used to just do a gem 'some_random_gem' and then bundle in the terminal and there were my dependencies. Now that I'm bumping my head against scala and play, I'm discovering that it might not be that easy on this playground.
I'm trying to runa sample application and this is the warning/error:
module not found: com.wingnest.play2#play21-frames-titan-plugin_2.10;1.3-module-2.4.4
Assume I do not know anything. Assume I have no experience and no scala background. I do have some, but can you give me a description on how to solve this?
I'm believe you will need the projects/build.scala file, so here it is:
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "play21-frames-titan-simple-app"
val appVersion = "1.2-module-2.3.2"
val titanVersion = "0.4.2"
val appDependencies = Seq(
"com.wingnest.play2" % "play21-frames-titan-plugin_2.10" % "1.3-module-2.4.4",
"com.thinkaurelius.titan" % "titan-cassandra" % {titanVersion},
javaCore
)
val main = play.Project(appName, appVersion, appDependencies).settings(
resolvers += "Oracle Releases" at "http://download.oracle.com/maven/"
)
}
First off, there are two types of plugins.
sbt plugins are declared in project/plugins.sbt using addSbtPlugin("organization" % "plugin-name" % "version") - the same way that Play is enabled (Play is nothing more than an sbt plugin).
You can find more info about it in the sbt plugins documentation.
Play plugins are normal dependencies but must be activated in the conf/play.plugins file (create it if non-existent) using the <priority>:<qualified-plugin-name> syntax, e.g. 500:se.radley.plugin.salat.SalatPlugin.
Unfortunately, this part of Play is not documented.
I'm currently working on a Scala project, recently, I want to include some Play framework features to my project. As I'm using sbt, I change my build.sbt to:
import play.Project._
name := "deploymentmanager"
version := "1.0"
scalaVersion := "2.10.3"
playScalaSettings
project.sbt is also updated:
// 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.2")
With those changes, I manage to build my project with Play's feature in it. However, when I'm writing code in Eclipse, all Play's features are marked as error: not found, object play. I wonder if there is any way to make Eclipse aware of Play library using sbt.
Try adding the Eclipse sbt plugin.
https://github.com/typesafehub/sbteclipse
And then do a >eclipse from the command line to regenerate the Eclipse specific files and import/reload that project in Eclipse.
I have a project using Playframework 2.2
I eclipsified it and in my code I write something like this:
import com.gargoylesoftware.htmlunit.WebClient
val client = new WebClient
Eclipse says everything's fine, but when I play run my application I get a following message:
[error] C:\workspace\kwiket\kwiketscala\app\service\parsers\HTMLParser.scala:11: object gargoylesoftware is not a member of package com
[error] import com.gargoylesoftware.htmlunit.WebClient
How could I fix this? What dependencies should I add to my project? Thanks
In the test configuration is HTMLUnit available, but you need it in the compile configuration.
Just update your libraryDependencies in build.sbt:
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
"net.sourceforge.htmlunit" % "htmlunit" % "2.13" //found on http://search.maven.org/#artifactdetails%7Cnet.sourceforge.htmlunit%7Chtmlunit%7C2.13%7Cjar section SBT
)
Restart SBT or execute reload.
I'm trying to use an SBT sub project with the Play Framework and I followed the instructions here.
I created the three directories, one containing the main play stuff, one dir being the sbt sub-project, and the last being the project directory with the Build.scala file.
At first I had problems with unresolved dependencies which was fixed with a build.properties file but now it doesn't want to include the play api when compiling the Build.scala file.
[info] Loading project definition from
/home/caskman/ScalaProjects/CorpusBrowserMultiTest/project
[info] Updating
{file:/home/caskman/ScalaProjects/CorpusBrowserMultiTest/project/}default-20bdad..
[info] Resolving org.scala-sbt#precompiled-2_10_0-m7;0.12.1 ...
[info] Done updating.
[info] Compiling 1 Scala source to
/home/caskman/ScalaProjects/CorpusBrowserMultiTest/project/target/scala-2.9.2/sbt0.12/classes...
[error] /home/caskman/ScalaProjects/CorpusBrowserMultiTest/project/Build.scala:3: not found: object play
[error] import play.Project._
[error] ^
[error] one error found
Here's Build.scala
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "PlayProject"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
// Add your project dependencies here,
jdbc,
anorm
)
val subProject = Project("subProject",file("subProject-dir"))
val main = play.Project(appName, appVersion, appDependencies, path = file("playProject"))
.dependsOn(subProject)
}
Are you sure the Play plugin is correctly loaded ? Without it, the Play library cannot be used in the Build file (or anywhere else).
As explained here, the project/plugins.sbt file must contain the plugin definition.
You can look at these samples to have working examples of this file:
// 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" % Option(System.getProperty("play.version")).getOrElse("2.0"))
So I've been trying to get IDEA 12.0 to work with Play 2.1.0 and Scala 2.10.0. I've just about given up because it's not working for me the way I want it to. Here is a copy of my build.properties, Build.scala, and plugins.sbt. I followed the approach on the playframework site to execute idea with-sources=yes in the play console. I've also tried adding sbt-idea plugin version 1.3.0-SNAPSHOT as seen in plugins.sbt, but nothing seems to work if I want to reference a new view template I just created or a new route. The only way I can work in IDEA is if I have a console open and run sbt compile, go back to IDEA, and it will refresh itself and recognize the new view templates or routes.
plugins.sbt
logLevel := Level.Warn
scalaVersion := "2.10.0"
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Sonatype snapshots to get sbt-idea 1.3.0-SNAPSHOT
//resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.1.0")
//addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.3.0-SNAPSHOT")
build.properties
sbt.version=0.12.2
Build.scala
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "admin-application"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
// Add your project dependencies here,
jdbc,
anorm
)
val main = play.Project(appName, appVersion, appDependencies).settings(
// Add your own project settings here
)
}
If you use IDEA Community edition, there is a SBT Console plugin (see http://plugins.jetbrains.com/plugin?pluginId=5007) that allows you to compile / run your Play project directly in the editor. That's the way I work every day and it is fine (I use the ~run command and then don't care anymore).
You may also add a remote debugger in IDEA that listens to you local server (it it is run with debug mode on) and use it as usual.
If you use IDEA Ultimate edition, JetBrains released a Play Framework plugin that seems to work fine (but I haven't tested it yet). Have a look at these tutorials:
http://confluence.jetbrains.com/display/IntelliJIDEA/Play+Framework+2.0 or
http://www.jamesward.com/2013/01/23/video-create-and-run-play-framework-apps-in-intellij
Hope this helps.
I think this is how it work currently. As suggested by #pedrofurla, you can keep ~run running on sbt/play console. Sadly, IMO there is no other way IntelliJ can compile your scala views automatically.
Just add to project/plugins.sbt the following and re-run play idea
// FIX SBT IDEA PLAY 2.1
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.1.0")