tl;dr @schleichardt 的答案是有效的 - 您需要将以下内容添加到build.sbt
文件中:
unmanagedSourceDirectories in Compile += file("other")
解释归结为检查compile
任务的依赖关系。用来inspect tree compile
找出它们。
[proj1]> inspect tree compile
[info] compile:compile = Task[sbt.inc.Analysis]
[info] +-compile:compile::compileInputs = Task[sbt.Compiler$Inputs]
[info] | +-compile:scalacOptions = Task[scala.collection.Seq[java.lang.String]]
[info] | +-compile:sources = Task[scala.collection.Seq[java.io.File]]
[info] | +-*/*:sourcePositionMappers = Task[scala.collection.Seq[scala.Function1[xsbti.Position, scala.Option[xsbti.Position]]]]
[info] | +-*/*:maxErrors = 100
[info] | +-*:compilers = Task[sbt.Compiler$Compilers]
[info] | +-compile:compile::streams = Task[sbt.std.TaskStreams[sbt.Init$ScopedKey[_ <: Any]]]
[info] | | +-*/*:streamsManager = Task[sbt.std.Streams[sbt.Init$ScopedKey[_ <: Any]]]
[info] | |
[info] | +-compile:incCompileSetup = Task[sbt.Compiler$IncSetup]
[info] | +-*/*:compileOrder = Mixed
[info] | +-compile:dependencyClasspath = Task[scala.collection.Seq[sbt.Attributed[java.io.File]]]
[info] | +-compile:classDirectory = target/scala-2.10/classes
[info] | +-*/*:javacOptions = Task[scala.collection.Seq[java.lang.String]]
[info] |
[info] +-compile:compile::streams = Task[sbt.std.TaskStreams[sbt.Init$ScopedKey[_ <: Any]]]
[info] +-*/*:streamsManager = Task[sbt.std.Streams[sbt.Init$ScopedKey[_ <: Any]]]
[info]
如您所见,任务取决于compile:sources
任务。该任务又取决于compile:unmanagedSources
使用该compile:unmanagedSourceDirectories
设置的任务。
[proj1]> inspect tree compile:sources
[info] compile:sources = Task[scala.collection.Seq[java.io.File]]
[info] +-compile:unmanagedSources = Task[scala.collection.Seq[java.io.File]]
[info] | +-compile:unmanagedSourceDirectories = List(/Users/jacek/sandbox/stackoverflow/proj1/src/main/scala, /Users/jacek/sandbox/stackoverflow/proj1/src/main/java, /Users/..
[info] | | +-compile:javaSource = src/main/java
[info] | | | +-compile:sourceDirectory = src/main
[info] | | | +-*:sourceDirectory = src
[info] | | | | +-*:baseDirectory = /Users/jacek/sandbox/stackoverflow/proj1
[info] | | | | +-*:thisProject = Project(id: proj1, base: /Users/jacek/sandbox/stackoverflow/proj1, aggregate: List(), dependencies: List(), configurations: List(compile..
[info] | | | |
[info] | | | +-compile:configuration = compile
[info] | | |
[info] | | +-compile:scalaSource = src/main/scala
[info] | | | +-compile:sourceDirectory = src/main
[info] | | | +-*:sourceDirectory = src
[info] | | | | +-*:baseDirectory = /Users/jacek/sandbox/stackoverflow/proj1
[info] | | | | +-*:thisProject = Project(id: proj1, base: /Users/jacek/sandbox/stackoverflow/proj1, aggregate: List(), dependencies: List(), configurations: List(compile..
[info] | | | |
[info] | | | +-compile:configuration = compile
[info] | | |
[info] | | +-*:baseDirectory = /Users/jacek/sandbox/stackoverflow/proj1
[info] | | +-*:thisProject = Project(id: proj1, base: /Users/jacek/sandbox/stackoverflow/proj1, aggregate: List(), dependencies: List(), configurations: List(compile, runt..
[info] | |
[info] | +-*/*:excludeFilter = sbt.SimpleFileFilter@7ced8ea7
[info] | +-*:baseDirectory = /Users/jacek/sandbox/stackoverflow/proj1
[info] | +-*/*:unmanagedSources::includeFilter = sbt.SimpleFilter@1beb6bba
[info] | +-*/*:sourcesInBase = true
[info] |
[info] +-compile:managedSources = Task[scala.collection.Seq[java.io.File]]
[info] +-compile:sourceGenerators = List()
[info]
该compile:unmanagedSourceDirectories
设置引用“非托管源目录,其中包含手动创建的源”。
[proj1]> inspect compile:unmanagedSourceDirectories
[info] Setting: scala.collection.Seq[java.io.File] = List(/Users/jacek/sandbox/stackoverflow/proj1/src/main/scala, /Users/jacek/sandbox/stackoverflow/proj1/src/main/java, /Users/jacek/sandbox/stackoverflow/proj1/other)
[info] Description:
[info] Unmanaged source directories, which contain manually created sources.
[info] Provided by:
[info] {file:/Users/jacek/sandbox/stackoverflow/proj1/}proj1/compile:unmanagedSourceDirectories
[info] Defined at:
[info] (sbt.Defaults) Defaults.scala:161
[info] /Users/jacek/sandbox/stackoverflow/proj1/build.sbt:1
[info] Dependencies:
[info] compile:javaSource
[info] compile:scalaSource
[info] *:baseDirectory
[info] Reverse dependencies:
[info] compile:unmanagedSources
[info] compile:sourceDirectories
[info] Delegates:
[info] compile:unmanagedSourceDirectories
[info] *:unmanagedSourceDirectories
[info] {.}/compile:unmanagedSourceDirectories
[info] {.}/*:unmanagedSourceDirectories
[info] */compile:unmanagedSourceDirectories
[info] */*:unmanagedSourceDirectories
[info] Related:
[info] test:unmanagedSourceDirectories
该设置属于scala.collection.Seq[java.io.File]
类型,并且要将元素附加到 seq,您可以使用+=
方法。
话虽如此,该build.sbt
文件应如下所示:
unmanagedSourceDirectories in Compile += (baseDirectory / "other").value
您不必使用该baseDirectory
设置,但它使基本目录明确。