gpt4 book ai didi

sbt - 为什么我的 sourceDirectories 设置在 sbt 中不起作用?

转载 作者:行者123 更新时间:2023-12-04 18:12:12 25 4
gpt4 key购买 nike

我正在阅读 SBT Getting Started指导。该页面显示 sourceDirectories设置为例。为了自己尝试,我将以下内容放入我的 build.sbt文件,用于基本的“hello world”项目。

sourceDirectories in Compile := Seq(file("other"))

(附加 +=++= 也不起作用。)

我在 <base-dir>/other 中有源文件并在 <base-dir>/src/main/scala .我跑了 sbt并输入 compile .它忽略了设置:
> compile
[info] Compiling 1 Scala source to /Learning/Scala/proj1/target/scala-2.9.2/classes...
[error] /Learning/Scala/proj1/src/main/scala/hello.scala:7: not found: value Foo
[error] println(Foo.foo)
Foo对象在 other 中的 foo.scala 中定义源目录。

我错过了什么?

最佳答案

tl;博士 The answer by @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设置,但它使基本目录显式。

关于sbt - 为什么我的 sourceDirectories 设置在 sbt 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13585437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com