scala 2.10Mx with playframework 2 - scala

How to use scala 2.10Mx with play 2.x.x?
I tried adding scalaVersion := "2.10.0-M3" to project/Build.scala but had no effect.
Here's my project/Build.scala:
import sbt._
import Keys._
import PlayProject._
object ApplicationBuild extends Build {
val appName = "dashboard-server"
val appVersion = "1.0-SNAPSHOT"
resolvers += "Local Ivy Repository" at "file://"+Path.userHome.absolutePath+"/.ivy2/cache"
scalaVersion := "2.10.0-M3"
val appDependencies = Seq(
"mysql" % "mysql-connector-java" % "5.1.10"
)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
// Add your own project settings here
)
}
I'm using sbt 0.11.3

There is a ticket in the play bugtracker: https://play.lighthouseapp.com/projects/82401/tickets/650-support-for-scala-210-m6
The answer is you currently cannot use play 2 with scala 2.10 because of akka.

play 2.0.x doesn't work with Scala 2.10.
the Play 2.1 branch does, but as of the time i write this (25 Oct 2012), you need to build the development branch from source, and the development branches are still under active development. TLDR: not yet suitable for production apps, give it a couple months

Well, actually you can do it. I described details in my answer here.
But in few words you need to specify few things in Build.scala.
Switching version by setting scalaVersion to 2.10.1 didn't help me because SBT still goes to repository and gets pieces of 2.10.0. So I told SBT to use local copy of Scala by setting following variables
scalaVersion := "2.10.1-local",
autoScalaLibrary := false,
scalaHome := Some(file("/Program Files (x86)/scala/"))

Related

How to add Google ML Kit dependency to SBT project?

When adding the Google ML Kit dependency to our SBT project, it successfully compiles, yet it cannot resolve imports to the com.google.mlkit package.
Here is a sample build.sbt file, using barcode-scanning as an example:
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.8"
lazy val root = (project in file("."))
.settings(
name := "test-google-mlkit"
)
resolvers += "Google Maven" at "https://maven.google.com/"
libraryDependencies += "com.google.mlkit" % "barcode-scanning" % "17.0.2" // % "runtime"
This successfully compiles, but we cannot resolve an import to com.google.mlkit, with or without the "runtime" flag (as indicated on the maven repo).
object mlkit is not a member of package com.google
Is it possible to use Google's ML Kit in a Scala project? What are we missing? Any help is appreciated.
To solve the import problem just change the resolvers to:
resolvers += "google repository" at "https://dl.google.com/android/maven2"

Can I create a proto jar for scalaVersion 2.11/2.12 and use it within the same sbt under different sub-project?

I have a set of .proto files (protobuf) which I generate java from using scalapb. I also have in the same sbt 2 sub-projects, one is scalaVersion 2.11 compatible (can't upgrade it to 2.12 due to missing packages) and the other one is scala 2.12.
I created a sub-project to hold my proto, and by default 2.12 is used and my 2.12 sub-project can use it, but my 2.11 can't.
I set the crossScalaVersions to 2.11/2.12, I compiled my project with both, which passed, but then even then I was unable to get the 2.11 sub-project to find that code.
I am "wondering" if that is something supported, or if there is a track I could use a single location to hold my .proto yet have my 2 sub-projects using the same sbt file use those.
lazy val scala212 = "2.12.13"
lazy val scala211 = "2.11.12"
lazy val supportedScalaVersion = List(scala212, scala211)
ThisBuild / scalaVersion := scala212
lazy val root = (project in file("."))
.aggregate(proto, subproject1, subproject2)
.settigns(
crossScalaVersions := Nil,
publish / skip := true
)
lazy val proto = project
.settings(
crossScalaVersions := supportedScalaVersions,
name := "proto",
libraryDependencies += "com.trueaccord.scalapb" %% "scalapb-runtime" % com.trueaccord.scalapb.compiler.Version.scalapbVersion % "protobuf",
PB.targets in Compile := Seq(
scalapb.gen(grpc = false) -> (sourceManaged in Compile).value / "protobuf"
)
)
lazy val subproject1 = project
.dependsOn(proto)
lazy val subproject2 = project
.settings(
scalaVersion := scala211
)
.dependsOn(proto)
So, from the above, if I do sbt "+ proto" I can compile both versions. If I do sbt subproject1/compile it works too. Using sbt subproject2/compile fails indicating that it cannot find the 2.11:proto jar file.
Either, I would like the above somehow to work nicely, or any other trick that I could generate the code from the same proto location but within subproject1/subproject2 would be appreciated.
You could try the sbt-projectmatrix plugin:
https://github.com/sbt/sbt-projectmatrix
The idea is to have separate sbt subprojects for the different Scala versions, so you can simply reference the relevant subproject when calling dependsOn.
I think this plugin is going to end up in sbt some day as it's a much better solution in general than the current built-in stateful cross compilation support, and it's developed by Eugene Yokota, who is also an sbt developer.

scala reference sbt project version

I have a scala play application; I am trying to expose health check for our service. Part of the health check I would like to capture the project artifact version.
Can I know how I can reference project artifact version from health check controller in play application. We are making use of sbt for the build.
sample sbt file
import root.sbt.Keys._
import com.typesafe.sbt.SbtNativePackager._
import NativePackagerKeys._
import play.PlayScala
name := "artifact-name"
version := "0.5"
scalaVersion := "2.11.1"
javacOptions ++= Seq("-source", "1.7", "-target", "1.7")
scalacOptions += "-target:jvm-1.7"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
The xsbt-reflect plugin gives you access to the SBT variables at runtime.
All you need to do inside of your health route is return
Reflect.version

How to avoid adding a 'root' scala sbt project in IntelliJ when defining github dependencies?

I'm using IntelliJ with SBT plugin and I've added the following lines to build.sbt in order to add a dependency to a private github repository:
lazy val g = RootProject(uri("ssh://git#github.com/XXXX/myrepo.git"))
lazy val root = project in file("myproject") dependsOn g
After running sbt, my referenced project is successfully cloned, but build fails due to output path clashes between my base project and a root project that is automatically added each time I refresh sbt after modifying build.sbt.
I was having this same issue awhile back.
I'm not sure what causes it but I know that if you use the multi-project setup for sbt (root/project/build.scala) instead of the simple one (root/build.sbt) Intellij respects your settings.
Try the multi-project setup like this and see if it solves your problem:
import sbt.Keys._
import sbt._
lazy val g = RootProject(uri("ssh://git#github.com/XXXX/myrepo.git"))
object MyProjectBuild extends Build {
lazy val project = Project("myproject", file(".")) // <-- Make sure to name your project what you want the module to be named
.settings(
name := "myproject", // <-- Same here
version := "1.0",
scalaVersion := "2.11.4",
libraryDependencies ++=Seq(
"org.scalatest" % "scalatest_2.11" % "2.2.0" % "test",
)
).dependsOn(g)
}

How do I get Intellij IDEA 12.0 to work with Play Framework 2.1.0 app and Scala 2.10.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")