How to add Google ML Kit dependency to SBT project? - scala

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"

Related

Scala libraries incompatibility

akka-actor_2.13-2.5.23.jar of play-scala-seed build path is cross-compiled with an incompatible version of Scala (2.13.0). In case this report is mistaken, this check can be disabled in the compiler preference page.
I have many errors of this type in my scala project. How do I resolve such errors?
I am using Scala IDE.
build.sbt:
name := """play-scala-seed"""
organization := "com.example"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.13.0"
libraryDependencies += guice
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "4.0.3" % Test
// Adds additional packages into Twirl
//TwirlKeys.templateImports += "com.example.controllers._"
// Adds additional packages into conf/routes
// play.sbt.routes.RoutesKeys.routesImport += "com.example.binders._"
I guess I need to change Scala installation to 2.13, right? ( I am referring to the Scala installation option that shows up in the project properties after right clicking on the project in the IDE )
But, the only options available in the dropdown are 2.10,2.11 and 2.12. How do I add 2.13 into my IDE?
The solutions in similar questions did not work for me.

Spark-Scala build.sbt libraryDependencies UnresolvedDependency

i'm trying to import a dependency in my build.sbt file from here
https://github.com/dmarcous/spark-betweenness.
When i hover on the error it says:
Expression type ModuleID must confirm to Def.SettingsDefinition in SBT file
Unresolved Dependency
I am new in scala so my question may be silly.Thanks in advance
It is still unclear how your build configuration looks like, but the following build.sbt works (in the sense that it compiles and does not show the error that you mentioned):
name := "test-sbt"
organization := "whatever"
version := "1.0.0"
scalaVersion := "2.10.7"
libraryDependencies += "com.centrality" %% "spark-betweenness" % "1.0.0"
Alternatively, if you have a multi-project build, it could look like this:
lazy val root = project
.settings(
name := "test-sbt",
organization := "whatever",
version := "1.0.0",
scalaVersion := "2.10.7",
libraryDependencies += "com.centrality" %% "spark-betweenness" % "1.0.0"
)
However, you're probably going to find that it still does not work because it cannot resolve this dependency. Indeed, this library does not seem to be available neither in Maven Central nor in jcenter. It is also very old - it appears to only be published for Scala 2.10 and a very old Spark version (1.5), so most likely you won't be able to use it with recent Spark environments (2.x and Scala 2.11).

Play framework's sbt import maven module error

I am using Playframework 2.5.4 to serve as REST API endpoint in default sbt build, compile & run with activator.
This play module imports a core module in local maven (3.9), where types were defined. Such as:
package com.myCompany
case class User(
id: Option[UUID] = None,
username: String
)
Then play controller package will import com.myCompany.User.
Issue is, when activator compiles, it gives unknown parameter name: username
If I placed case class in play's models package, it compiles without error.
Below is my build.sbt
name := """api"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
filters,
"com.myCompany" % "core" % "1.0-SNAPSHOT"
)
routesGenerator := InjectedRoutesGenerator
resolvers ++= Seq(
"scalaz-bintray" at "http://dl.bintray.com/scalaz/releases",
Resolver.mavenLocal
// "Local Maven Repository" at "file:///home/pocheng/.m2/repository"
)
I suspect build.sbt file is having issue. Would appreciate any pointer. Thanks.

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 run playframework sample in Intelllij 13?

I am using Intellij 13 Ultimate and want to create a Play Framework sample. But I am unable to build this project because it always throws this error:
object index is not a member of package views.html
Ok(views.html.index("Your new application is ready."))
I have tried this on both Mac and Windows platforms, but the error is always the same.
How can I solve this?
The generation works just fine and all the paths are correctly added to the build. However the routes are not (yet) compiled by the plugins (scala+playframework), thus the reverse routing classes generated by play are not available for intellij.
You will have the same problem with the templates.
If you run a play compile (or a sbt compile), the classes will be generated and intellij should be able to pick them up and compile your project.
I found a trick here.
If you generate the play-scala project using activator command line activator [new my_first_project play-scala]. You'll get the following sbt build file.
name := """my_first_project"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test
)
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
But IF you create a project from intellj using NewProject->Scala-Play 2.x, you will get the following sbt.
name := "my_second_project"
version := "1.0"
lazy val `my_second_project` = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq( jdbc , cache , ws , specs2 % Test )
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
fork in run := false
after combine them. Ignore the name. And I set for in run to false
name := "my_second_project"
version := "1.0"
lazy val `my_second_project` = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq( jdbc , cache , ws , specs2 % Test )
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
fork in run := false
After doing that. Open the activator-generated project with Intellj, configure a run with Play 2.x run. Everything goes well.
By the way, if you open the activator-generated project before you change the sbt file. You might need to rm -r .idea
Hope that helps.
Running "play idea" in the new project root fixed it for me. The project should compile and run after reloading.
I only have this problem with projects created through Idea's New Project menu.
I have the same problem: in Idea 13 there are highlight errors there, but in Idea 12 everything is ok. The reason is that there is no Scala plugin for Idea 13, so for now it's impossible to get it to work in Idea 13.
The solution is to install Idea 12, go to Preferences -> Plugins, type "Scala" in find box, and install Scala plugin.