Hanxue
Hanxue

Reputation: 12766

Difference between scalaSource and sourceDirectories in sbt

What is the difference between scalaSource and sourceDirectories? I have a non-standard directory structure where source code lives in src/,

This line works in build.sbt:

scalaSource in Compile := file("src/")

but not

sourceDirectories in Compile := Seq(file("src/"))

Upvotes: 2

Views: 1132

Answers (2)

Seth Tisue
Seth Tisue

Reputation: 30453

Sources come in many kinds: Scala and Java, managed and unmanaged. sourceDirectories in Compile combines all of them, but you wouldn't normally want to set it directly; normally you'd set the more specific setting that applies to the particular kind of source you're trying to tell sbt the location of.

Note that baseDirectory.value / "src" would be more correct than file("src") (it works in more scenarios: subprojects, external projects, etc).

Upvotes: 3

Rin malavi
Rin malavi

Reputation: 879

I can't tell you the whole picture, someone who worked on sbt may see this post later. Till then, here is how I reason about this things: inspect

> inspect actual compile:scalaSource
[info] Description:
[info]  Default Scala source directory.
[info] Dependencies:
[info]  compile:sourceDirectory
[info] Reverse dependencies:
[info]  compile:unmanagedSourceDirectories
[info] Delegates:
[info]  compile:scalaSource

> inspect actual compile:sourceDirectories
[info] Description:
[info]  List of all source directories, both managed and unmanaged.
[info] Dependencies:
[info]  compile:unmanagedSourceDirectories
[info]  compile:managedSourceDirectories
[info] Delegates:
[info]  compile:sourceDirectories
[info]  *:sourceDirectories
[info]  {.}/compile:sourceDirectories

Now this is how I interpret this: sourceDirectories are ... well ... completely informal ...

Lets see how this is relevant to something like compile:

> inspect compile
[info] Dependencies:
[info]  compile:compile::compileInputs  <----
[info]  compile:compile::streams

> inspect compile:compile::compileInputs
[info] Dependencies:
...
[info]  compile:compile::sources  <----
...

> inspect compile:compile::sources
[info] Provided by:
[info]  {file:<build-uri>}<project-id>/compile:sources    
[info] Delegates:
[info]  compile:compile::sources
[info]  compile:sources  <----

This task is delegated, we can see where we came from in Reverse dependencies with inspect actual, regular inspect woudn't show them.

> inspect actual compile:sources
[info] Description:
[info]  All sources, both managed and unmanaged.
[info] Reverse dependencies:
[info]  compile:doc
[info]  compile:compile::compileInputs
[info] Dependencies:
[info]  compile:unmanagedSources   <----
[info]  compile:managedSources

> inspect compile:unmanagedSources
[info] Dependencies:
[info]  compile:unmanagedSourceDirectories
...

> inspect compile:unmanagedSourceDirectories
[info] Dependencies:
[info]  compile:javaSource
[info]  compile:scalaSource  <----
[info] Reverse dependencies:
[info]  compile:sourceDirectories
[info]  compile:unmanagedSources

Hope this helps.

Upvotes: 1

Related Questions