3

I had the following code like the following that worked previously:

.settings(watchSources := watchSources.value.filterNot(_.getPath.contains("target")))

In SBT 1.x this results in:

error: value getPath is not a member of sbt.Watched.WatchSource
x.getPath.contains("target")

Expanding the code slightly by adding a type to the function paramemter of filterNot:

.settings(watchSources := (watchSources.value.filterNot{x: File =>
  x.getPath.contains("target")
}))

we get a separate error:

[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 =>
                                                             ^

The strange thing is that IntelliJ seems to think the code looks fine as is (I did restart IntelliJ after updating my build.properties with the latest version of SBT) - it sees the value x as a File, not as a WatchSource, and it indicates that watchSources.value is of type Seq[File].

This related but more general question ( Remove or Exclude WatchSource in sbt 1.0.x ) doesn't seem to have garnered any attention thus far.

Justin Kaeser
  • 5,868
  • 27
  • 46
bbarker
  • 11,636
  • 9
  • 38
  • 62
  • 1
    `Source`'s `base: File` constructor parameter has been changed to be a `val` recently, but unfortunately the patched version appears not to be released yet: https://github.com/sbt/io/pull/123/commits/3564f5050c9c93bb4b80c45f45029a507fcefa66 – dkim Feb 14 '18 at 19:50
  • Thanks, sounds vaguely promising, but I'm woefully ignorant of SBT, so I don't understand the direct implications. – bbarker Feb 14 '18 at 20:32
  • I can confirm it isn't an issue in 0.13.7, and happily everything else in my build setup also works with 0.13.7 – bbarker Feb 15 '18 at 14:28
  • 1
    Yes, the situation can be explained as follows: `WatchSources` is of type `TaskKey[Seq[File]]` in 0.13 while it is of type `TaskKey[Seq[WatchSource]]` in 1.x. `WatchSource` is an alias of `sbt.internal.io.Source`, which did not allow us to access its `File` component, `base`, until recently. – dkim Feb 15 '18 at 15:24
  • Any updates on this - just upgraded to 1.0.4 and having trouble. – BatteryAcid Jun 07 '18 at 18:31
  • @dkim you said it didn't allow us to access the `File` component, `base`, until recently. Does that mean this is fixed now? (e.g. in sbt 1.2.x) It would be useful if this question could be answered taking into account recent changes in sbt – Ben McCann Aug 27 '18 at 17:40
  • 1
    @BenMcCann Thank you for reminding me. According to GitHub, the commit above has been incorporated into sbt 1.2.0. So I think that the OP's code can be written now as follows: `.settings(watchSources := watchSources.value.filterNot(_.base.getPath.contains("target")))` – dkim Aug 28 '18 at 21:54
  • So far, the above code seems to compile (using sbt 1.2.8). I'll just note that some recent versions of IntelliJ flag it as erroneous, while it is not. I'm revisiting all of this again and need to check to see if my other SBT errors were fixed in another branch! Thanks. – bbarker Jun 13 '19 at 19:30

0 Answers0