我将 JAVA_HOME 设置为 C:\Progra~1\Java\jdk1.6.0_37 并且 sbt 将依赖项解析为 C:\Program Files\Java\jdk1.6.0_37\jre\lib\rt.jar。Sbt 使用 java.io.File.equals() 在这种情况下是不正确的:
在 sbt/compile/inc/Incremental.scala 中:
def externalBinaryModified(entry: String => Option[File], analysis: File => Option[Analysis], previous: Stamps, current: ReadStamps)(implicit equivS: Equiv[Stamp]): File => Boolean =
dependsOn =>
analysis(dependsOn).isEmpty &&
orTrue(
for {
name <- previous.className(dependsOn)
_ = println("Name: " + name)
e <- entry(name)
_ = println("entry: " + e)
} yield {
val resolved = Locate.resolve(e, name)
println("resolved: " + resolved)
println("dependsOn: " + dependsOn)
println("resolved != dependsOn: " + (resolved != dependsOn))
(resolved != dependsOn) || !equivS.equiv(previous.binary(dependsOn), current.binary(resolved))
}
)
给出以下输出:
Name: java.lang.Object
entry: c:\Progra~1\Java\jdk1.6.0_37\jre\lib\rt.jar
resolved: c:\Progra~1\Java\jdk1.6.0_37\jre\lib\rt.jar
dependsOn: c:\Program Files\Java\jdk1.6.0_37\jre\lib\rt.jar
resolved != dependsOn: true
因此,sbt 总是认为 rt.jar 被改变了。
解决方法是将 JAVA_HOME 设置为 "c:\Program Files\Java\jdk1.6.0_37" 解决方案是:
resolved.getCanonicalPath != dependsOn.getCanonicalPath