Ivan
Ivan

Reputation: 64227

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

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?

Upvotes: 8

Views: 3025

Answers (1)

Kipton Barros
Kipton Barros

Reputation: 21112

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.

Upvotes: 18

Related Questions