4

我唯一的猜测是我的构建配置有问题,但每次我编译它都会重新编译所有内容。深入挖掘“最后一次编译”总是告诉我

> compile
[info] Compiling 28 Scala sources and 78 Java sources to /home/me/foo/target/scala-2.10/classes...
[warn] Note: Some input files use unchecked or unsafe operations.
[warn] Note: Recompile with -Xlint:unchecked for details.
[success] Total time: 34 s, completed Nov 8, 2013 12:35:18 PM
> last compile
[debug] 
[debug] Initial source changes: 
[debug]     removed:Set(/home/me/foo/scala/Bar.scala, ...)
[debug]     added: Set(scala/Bar.scala, ...)
[debug]     modified: Set()
...
[debug] Recompiling all 106 sources: invalidated sources (56) exceeded 50.0% of all sources
...

对于我的每个 Scala 源文件,它们在删除集中包含它们的完全限定路径,并且在添加集中它们具有我在我的配置中使用的相对路径。我有一个混合的 Scala 和 Java 项目,这可能是一个问题吗?尽管“最后一次编译”从未提及 Java 文件。

我的配置如下:

import sbt._
import Keys._

object MyBuild extends Build {
  val buildSettings = Defaults.defaultSettings ++ Seq(
    scalaVersion := "2.10.2"
  )
  val jettyVersion = "7.6.7.v20120910"

  val webHome = System.getenv("WEB_HOME")

  val webJars = 
  Seq("servlet-api-2.5.jar", 
      "annotations.jar",
      "jetty-server-" + jettyVersion + ".jar",
      "jetty-client-" + jettyVersion + ".jar",
      "jetty-http-" + jettyVersion + ".jar",
      "jetty-http-" + jettyVersion + ".jar")
    .map(webHome + "/lib/java/" + _)
  val classes = Seq("build/jars/Foo.classes")

  val jarPath = (webJars ++ classes).map(file).classpath

  val sourcePaths = 
    inConfig(Compile)(Defaults.configSettings) ++
    Seq(
      unmanagedSourceDirectories in Compile += file("scala"),
      unmanagedSourceDirectories in Compile += file("build/java"),
      unmanagedSourceDirectories in Compile += file("java"),
      unmanagedJars in Compile ++= jarPath)

  val root = Project("root", file("."), settings = (buildSettings ++ sourcePaths))
}

有什么明显的我在这里搞砸了吗?

4

1 回答 1

0

我将以下行放在 build.sbt 的末尾:

scalaSource in Compile := baseDirectory.value / "src"

解决了我的问题,因为由于 IDE 兼容性,我的源代码直接位于src没有mainscala文件夹下。

于 2013-12-18T16:43:18.010 回答