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.
Related
I have an sbt project containing 2 play sub-projects with 2 different versions of play (and basically 2 different versions of Scala: 2.12 and 2.10). Is there a way to use two versions of the play plugin?
This is my plugins.sbt:
resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
resolvers += "Akka Snapshot Repository" at "https://repo.akka.io/snapshots/"
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.7")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.7")
And this is build.sbt:
lazy val global = Project("root",file("."))
lazy val play28 = Project( "play_2.8_subproject" , file("subs/ply28/")).settings(
libraryDependencies ++= Seq( jdbc , ehcache , ws , specs2 % Test , guice ),
scalaVersion := "2.12.2"
).enablePlugins(PlayScala)
lazy val play23 = Project( "play_2.3_subproject" , file("subs/pl23/")).settings(
scalaVersion := "2.10.5",
libraryDependencies ++= Seq( jdbc , ws )
).enablePlugins(PlayScala)
I can run the play 2.8 subproject. Nevertheless, play plugin 2.8 is still not resolved with Scala 2.10 when trying to run the play 2.3 project.
(play_2.3_subproject/*:update) sbt.ResolveException: unresolved dependency:
com.typesafe.play#play-server_2.10;2.8.7: not found
You get the idea, I want to switch between the two play projects and enable the appropriate plugin version for each subproject.
Is that possible in the first place ? If yes how can I achieve the desired behaviour ?
Note I am using sbt 0.13.
To sum up the discussion from the comments, it is probably impossible. One of the difficulties for example is to enable PlayScala in build.sbt. As described in The /build.sbt file (version 2.8) or at Auto Plugins and plugin settings (version 2.3), in both versions you enable the plugin:
lazy val root = (project in file(".")).enablePlugins(PlayScala)
when PlayScala is defined at play.sbt.PlayScala in both versions.
Having that said, even if it would be possible to build such a structure, it will be really hard to maintain, as there are breaking changes between Play 2.3 and Play 2.8, as elaborated in:
Play 2.4 Migration Guide
Play 2.5 Migration Guide
Play 2.6 Migration Guide
Play 2.7 Migration Guide
Play 2.8 Migration Guide
The best approach that should be taken in order to upgrade the Play version, is do it in one shot. Upgrade Scala, Play, and sbt all at once to latests. It will probably take less time then figuring out how to have both Play versions in the same project.
For future maintenance, the best will be to upgrade once a new version is out there. This way you don't have to do much changes to keep it up. Furthermore, you get the latest updates which usually includes security vulnerabilities fixes, performance improvements, and bug fixes, along with new features.
I am very new to SBT, Breeze and IntelliJ, though I have a decent grasp of Scala and I am trying to install the Breeze library, which I think is managed.
What I've done:
I followed the instructions on this page and added this script to the build.sbt file in my project:
libraryDependencies ++= Seq(
// other dependencies here
"org.scalanlp" %% "breeze" % "0.10",
// native libraries are not included by default. add this if you want them (as of 0.7)
// native libraries greatly improve performance, but increase jar sizes.
"org.scalanlp" %% "breeze-natives" % "0.10"
)
resolvers ++= Seq(
// other resolvers here
"Sonatype Releases" at "https://oss.sonatype.org/content/repositories/releases/"
)
// Scala 2.9.2 is still supported for 0.2.1, but is dropped afterwards.
scalaVersion := "2.11.1" // or 2.10.3 or later
I then ran sbt update in the project directory (via the terminal), and saw that all the pieces of Breeze downloaded.
I then tried re-running sbt update, but this did not trigger another download.
Issue:
The problem is that I cannot access the library via IntelliJ. import breeze._ gives the standard Cannot resolve symbol breeze and I couldn't find any mention of Breeze in "Project Structure." It isn't in the lib directory of the project either.
Am I missing a step?
Sounds like a bug in the IntelliJ project, try removing the .idea directory from the project directory and then re-import the project into IntelliJ using the wizard.
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.
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")
I had a lot of trouble getting sbt-idea to work in my Scala 2.10 project.
I tried compiling sbt-idea from its git repo, making sure that to have set
scalaVersion := "2.10.0-RC5"
in build/Build.scala, and using publish-local command to compile it in git. But I nevertheless keep getting
[error] sbt.IncompatiblePluginsException: Binary incompatibility in plugins detected.
when I then use that in my published version, say by simply adding
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.3.0-SNAPSHOT")
to the project/plugins.sbt file.
Don't think you need to build SBT for Scala 2.10. I keep my gen-idea and eclipse project generators in the global build.sbt file and it works for all my projects (or so it seems ;-)
I'm using Ubuntu, so where the SBT config files are saved on your computer may be different.
Create a folder called plugins under the hidden sbt directory. On Linux this is located at ~/.sbt (where tilde is an alias for your home directory). So now you should have ~/.sbt/plugins
Then create a file called build.sbt under this directory and add the following to it:
resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
resolvers += "Sonatype releases" at "https://oss.sonatype.org/content/repositories/releases/"
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0-SNAPSHOT")
To test, I just generated a scala 2.10 project with it, and it seems fine.
Oh, the file above also adds support for the eclipse command in SBT if you want to generate Scala-IDE projects.
I was able to use an older version of gen-idea by adding the following to project/plugins.sbt in the project itself:
import sbt._
import Defaults._
libraryDependencies += sbtPluginExtra(
m = "com.github.mpeltonen" % "sbt-idea" % "1.2.0", // Plugin module name and version
sbtV = "0.12", // SBT version
scalaV = "2.9.2" // Scala version compiled the plugin
)