How to add jdbc dependency to Play project? - scala

I'm using play 2.2.2.
I'd like to enable jdbc library in a Play/Scala project as mentioned in Accessing an SQL database.
Here's my rootproject/project/plugins.sbt:
libraryDependencies ++= Seq(
jdbc
"com.google.zxing" % "core" % "2.0",
"mysql" % "mysql-connector-java" % "5.1.27",
"com.typesafe.slick" %% "slick" % "2.1.0",
"org.slf4j" % "slf4j-nop" % "1.6.4"
)
While compiling the project, I get following jdbc not found error,
$ /usr/local/play-2.2.2/play compile
/packup/smartad-core/project/plugins.sbt:8: error: not found: value jdbc
jdbc
^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q
My rootproject/build.sbt simply is
import play.Project._
name := "smartad-backend"
version := "1.0"
playScalaSettings
References
https://www.playframework.com/documentation/2.3.x/ScalaAnorm

You should combine both of those blocks into your build.sbt file. plugins.sbt is for adding sbt plugins, such as the play sbt plugin. But that's about it.
import play.Project._
name := "smartad-backend"
version := "1.0"
playScalaSettings
libraryDependencies ++= Seq(
jdbc,
...
)

Related

log4j2 in scala on sbt complie gives Unresolved dependencies path

I'm trying to use log4j2 in scala.
Below is my build.sbt
name := "trial"
version := "0.1"
scalaVersion := "2.13.1"
libraryDependencies += "org.apache.logging.log4j" %% "log4j-api" % "2.12.1"
libraryDependencies += "org.apache.logging.log4j" %% "log4j-core" % "2.12.1"
libraryDependencies += "org.apache.logging.log4j" %% "log4j-api-scala" % "2.12.1"
How to resolve these errors:
[warn] Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading org.apache.logging.log4j:log4j-api_2.13:2.12.1
sbt.librarymanagement.ResolveException: Error downloading org.apache.logging.log4j:log4j-api_2.13:2.12.1
not found: /Users/username/.ivy2/local/org.apache.logging.log4j/log4j-api_2.13/2.12.1/ivys/ivy.xml
Note :
There is no directory /Users/username/.ivy2/local/
but I can see there is /Users/username/.ivy2/cache/
and plugins log4j-api,core,api-scala are present in cache.
The IDE i'm using is IntelliJ IDEA.
There are multiple problems
You are using Scala 2.13 however the latest build of log4j-api-scala is for Scala 2.12.
The latest version of log4j-api-scala is 11.0 not 2.12.1
log4j-api and log4j-core are Java libraries so we should use single % instead of double%%

Scala SBT Cannot Add Dependency (geotrellis)

I'm new to Scala and working with IntelliJ Community Edition.
I open a new project and edit the build.sbt file to contain the following:
name := "test"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
"org.locationtech.geotrellis" %% "geotrellis-raster" % "1.0.0" % "1.1.0" ,
"org.locationtech.geotrellis" % "geotrellis-shapefile_2.11" % "1.1.0"
).map(_
.exclude("com.azavea.geotrellis", "geotrellis-proj4_2.11")
.exclude("com.azavea.geotrellis", "geotrellis-raster_2.11")
)
After that, I refresh the project, and I get the following errors in the error file:
[error] (*:ssExtractDependencies) java.lang.IllegalArgumentException: Cannot add dependency 'org.locationtech.geotrellis#geotrellis-raster_2.11;1.0.0' to configuration '1.1.0' of module default#test_2.11;1.0 because this configuration doesn't exist!
[error] (*:update) java.lang.IllegalArgumentException: Cannot add dependency 'org.locationtech.geotrellis#geotrellis-raster_2.11;1.0.0' to configuration '1.1.0' of module default#test_2.11;1.0 because this configuration doesn't exist!
What am I doing wrong here?
Main issue seems to be two different version numbers on one of your dependencies.
"org.locationtech.geotrellis" %% "geotrellis-raster" % "1.0.0" % "1.1.0"
Should be
"org.locationtech.geotrellis" %% "geotrellis-raster" % "1.0.0"
or
"org.locationtech.geotrellis" %% "geotrellis-raster" % "1.1.0"
if you want the 1.1.0 version

SBT - missing dependency

Well, my collaborator run code under build.sbt shown below without any problems while I get:
[error] /.../GameMap.scala:91: value revalidate is not a member of javax.swing.JFrame
[error] frame.revalidate()
[error] ^
[error] /.../GameMap.scala:92: value revalidate is not a member of java.awt.Container
[error] frame.getContentPane.revalidate()
[error] ^
I suspect, something is missing in build.sbt:
scalaVersion := "2.10.4"
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
// scalacOptions ++= Seq("-feature")
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.3.8",
"com.typesafe.akka" %% "akka-cluster" % "2.3.8",
"org.scala-lang" % "scala-swing" % "2.10.4"
)
What is it ?
My guess is that your running Java 6 and your collaborator is running Java 7
This is the Container documentation for java 6, which does not list a revalidate method inherited from Component.
And here is the java 7 documentation, which DOES list a revalidate method being inherited from Component
*The same can be stated for swing

Scala code build with sbt assembly , failing

I am using sbt 0.13.7 and Scala 2.11.4 on a Windows machine to compile my code into a fat jar, that I eventually want to run on a Linux machine.
Below is my build.sbt file:
import AssemblyKeys._
name := "Simple Project"
version := "1.0"
organization := "com.myorg"
scalaVersion := "2.11.4"
libraryDependencies ++= Seq(
// Spark dependency
"org.apache.spark" % "spark-core_2.10" % "1.2.0" % "provided",
// Third party libraries
"net.sf.jopt-simple" % "jopt-simple" % "4.3",
"joda-time" % "joda-time" % "2.0"
)
libraryDependencies += Defaults.sbtPluginExtra("com.eed3si9n" % "sbt-assembly" % "0.7.2", "0.11.2", "2.9.1")
// This statement includes the assembly plugin capabilities
assemblySettings
// Configure jar named used with the assembly plug-in
jarName in assembly := "my-project-assembly.jar"
// A special option to exclude Scala itself form our assembly jar, since Spark
// already bundles Scala.
assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeScala = false)
The error I am facing is:
build.sbt:16: error: type mismatch;
found : Seq[sbt.Project.Setting[_]]
required: sbt.internals.DslEntry
assemblySettings
^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
Are you using sbt-assembly 0.12.0? If so, you don't need assemblySettings any more since it's an auto plugin.
Edit:
You have to include
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.12.0")
in project/*.sbt like project/assembly.sbt, not build.sbt.

Can't compile 2.2 to 2.3 Migration

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.