sbt总是在虚假的源更改上进行完全重建

时间:2013-11-08 17:48:36

标签: scala sbt

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

> 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源文件,它们在remove集合中包含其完全限定的路径,并且在添加的集合中,它们具有我在配置中使用的相对路径。我有一个混合的Scala和Java项目,那么这可能是一个问题吗?虽然“last compile”从未提及过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))
}

有什么明显的东西我搞砸了吗?

1 个答案:

答案 0 :(得分:0)

我在build.sbt的末尾添加了以下行:

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

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