Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up managed dependencies in an SBT 0.11 project having Build.scala

Tags:

scala

sbt

I am building a simple Scala project with SBT 0.11.

All the code files are in ~/MyProject/src/main/scala/

~/MyProject/build.sbt is the following


name := "MyProject"

version := "1.0"

scalaVersion := "2.9.1"

libraryDependencies ++= Seq(
  "mysql" % "mysql-connector-java" % "5.1.+",
  "c3p0" % "c3p0" % "0.9.1.2",
  "org.apache.commons" % "commons-lang3" % "3.0.1",
  "commons-lang" % "commons-lang" % "2.6",
  "javassist" % "javassist" % "3.12.1.GA"
)

~/MyProject/project/Build.scala is the following


import sbt._

object MyProjectBuild extends Build {
  lazy val MyProject = Project("MyProject", file("."))
}

This seems to work almost fine. The project does compile and run. The project name is set correctly (if I don't use Build.scala, then the name seems to appear something like "default-????", despite it being specified in build.sbt).

But the problem is that dependencies do not seem to work - update command doesn't download anything. How to fix this? Do I need to specify my dependencies in Build.scala rather than in build.sbt in this case?

like image 307
Ivan Avatar asked Nov 03 '11 01:11

Ivan


People also ask

Which is the correct way to add dependencies in sbt file?

Library dependencies can be added in two ways: unmanaged dependencies are jars dropped into the lib directory. managed dependencies are configured in the build definition and downloaded automatically from repositories.

How do we specify library dependencies in sbt?

You can use both managed and unmanaged dependencies in your SBT projects. If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.

What is sbt dependency management?

Like in almost every build system, SBT allows you to define library dependencies which are resolved automatically, so you don't have to download and package required libraries by yourself.


1 Answers

Is it possible that you've already retrieved the project dependencies, but don't realize it because they are stored in the Ivy cache? You can view the managed classpath from the SBT console with the command

show managed-classpath

Recent versions of SBT do not store the managed dependencies in the project directory, unless the project is configured to do so. If you want, you can add the following to your build.sbt file:

retrieveManaged := true

This will create a ~/MyProject/lib_managed/ directory and contents.

like image 80
Kipton Barros Avatar answered Oct 19 '22 15:10

Kipton Barros