Reputation: 10498
Why doesn't sbt automatically add libraryDependencies to class path? I am trying to add jdbc-sqlite to my project however it can't find the driver. The lib dependency is being managed by sbt so it should be part of the class path. But I guess not, so how can I add it?
It feels like bad practice to have defined path references to these libraries that only exist on my box.
name := "CacheWarmer"
version := "0.1"
scalaVersion := "2.12.3"
mainClass in Compile := Some("process.Daemon")
libraryDependencies ++= Seq(
"org.xerial" % "sqlite-jdbc" % "3.20.0" % "test"
)
package process
import java.sql.Connection
import java.sql.DriverManager
import java.sql.ResultSet
import java.sql.SQLException
import java.sql.Statement
Code
object Daemon {
def main(args: Array[String]): Unit = {
//Gets java.sql.SQLException: No suitable driver found for jdbc:sqlite::memory:
val connection:Connection = DriverManager.getConnection("jdbc:sqlite::memory:")
}
}
Upvotes: 0
Views: 925
Reputation: 128071
You have put the sqlite-jdbc
dependency into the test
scope. Naturally, such dependencies are only available in the test classpath, but not in the "main" classpath. Usually you use the test
scope for test dependencies, e.g. test libraries like Scalatest or JUnit.
In order for a library to be available in your "main" classpath, you have to use the compile
scope, or, equivalently, not using a scope classifier at all:
libraryDependencies ++= Seq(
"org.xerial" % "sqlite-jdbc" % "3.20.0"
)
Upvotes: 2
Reputation: 2453
Maven central tells that to use that dependency in SBT you should use:
libraryDependencies += "org.xerial" % "sqlite-jdbc" % "3.20.0"
--> Notice there is no double %
The %%
tells sbt to append the current scala version to the artifact name. Assuming you are running scala 2.11:
libraryDependencies += "org.some" %% "myscala" % "3.20.0"
gets desuggered to:
`libraryDependencies += "org.some" % "myscala_2.11" % "3.20.0"`
Upvotes: 2