scalaapache-sparksbt

Does `sbt run`on a project install Scala compiler, interpreter and dependencies locally to the project?


If I am correct, Scala is usually installed by sbt for each of your Scala projects rather than being installed system-wide.

I created a simple example:

sbt new scala/hello-world.g8

When I run sbt run on a Scala sbt project, I saw several local directories created, for example target.

What does sbt run install and where?


Solution

  • does sbt run install them locally to the project?

    sbt resloves dependencies using Coursier since 1.3.0

    sbt 1.3.0+ uses Coursier to implement dependency management. Until sbt 1.3.0, sbt has used Apache Ivy for ten years.

    to a central repository on your local machine. We can show Coursier cache directory by executing

    csrCacheDirectory
    

    which on my machine gives

    /Users/mario_galic/Library/Caches/Coursier/v1
    

    Hence dependencies are not installed per-project within a directory local to the project. These dependencies are fetched remotely only once per version of the dependency the first time some project requires it, and then all other projects that depend on this same version fetch it from the local cache.

    To print the complete classpath used by sbt run execute

    show runtime:fullClasspath
    

    which outputs something like

    sbt:scala-runner-classpath> show runtime:fullClasspath
    [info] * Attributed(/Users/mario_galic/code/stackoverflow/scala-runner-classpath/target/scala-2.13/classes)
    [info] * Attributed(/Users/mario_galic/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.1/scala-library-2.13.1.jar)