Scala 如何在SBT1.x中使用WatchSource来过滤文件?
我有如下代码,类似于之前的工作:Scala 如何在SBT1.x中使用WatchSource来过滤文件?,scala,intellij-idea,sbt,intellij-scala,Scala,Intellij Idea,Sbt,Intellij Scala,我有如下代码,类似于之前的工作: .settings(watchSources := watchSources.value.filterNot(_.getPath.contains("target"))) 在SBT 1.x中,这导致: error: value getPath is not a member of sbt.Watched.WatchSource x.getPath.contains("target") 通过在filterNot的函数参数中添加类型,稍微扩展代码: .setti
.settings(watchSources := watchSources.value.filterNot(_.getPath.contains("target")))
在SBT 1.x中,这导致:
error: value getPath is not a member of sbt.Watched.WatchSource
x.getPath.contains("target")
通过在filterNot
的函数参数中添加类型,稍微扩展代码:
.settings(watchSources := (watchSources.value.filterNot{x: File =>
x.getPath.contains("target")
}))
我们得到一个单独的错误:
[info] Loading project definition from /home/brandon/workspace/CCRS/project
/home/brandon/workspace/CCRS/build.sbt:111: error: type mismatch;
found : sbt.File => Boolean
(which expands to) java.io.File => Boolean
required: sbt.Watched.WatchSource => Boolean
(which expands to) sbt.internal.io.Source => Boolean
.settings(watchSources := watchSources.value.filterNot{x: File =>
^
奇怪的是IntelliJ似乎认为代码看起来很好(我在用最新版本的SBT更新了build.properties
后重新启动了IntelliJ)-它将值x
视为文件,而不是监视源代码,它表示watchSources.value
的类型为Seq[File]
到目前为止,这个相关但更一般的问题()似乎没有引起任何关注。源代码的基:File
构造函数参数最近已更改为val
,但不幸的是,修补后的版本似乎还没有发布:谢谢,听起来很有希望,但是我对SBT一无所知,所以我不理解它的直接含义。我可以确认它在0.13.7中不是问题,而且很高兴我的构建设置中的其他所有内容也都适用于0.13.7。是的,这种情况可以解释如下:WatchSources
类型为TaskKey[Seq[File]]
在0.13中,而它在1.x中是类型为TaskKey[Seq[WatchSource]]
WatchSource
是sbt.internal.io.Source
的别名,直到最近才允许我们访问其文件组件base
。@Benmcann感谢您提醒我。根据GitHub的说法,上面的提交已经被合并到SBT1.2.0中。因此,我认为OP的代码现在可以按如下方式编写:.settings(watchSources:=watchSources.value.filterNot(u.base.getPath.contains(“target”))