This is an sbt plugin that aims to lower the latency between file system events and sbt tasks. It replaces the default watch service with a more highly optimized service that works well on all platforms.
Add
addSbtPlugin("com.swoval" %% "sbt-close-watch" % "1.3.2")
to your project/plugins.sbt. To apply the plugin globally, add those commands to
~/.sbt/1.0/plugins/watch.sbt
or ~/.sbt/0.13/plugins/watch.sbt
(creating the file if necessary).
The plugin can be configured with the following options:
- closeWatchAntiEntropy (default 35 milliseconds) -- Controls the anti-entropy parameter of the updated ~ command. Some programs touch a file a few times on save and this paramter prevent spurious builds if the same file is touched multiple times within this period.
- closeWatchFileCache -- Controls the file cache used by the plugin to list source files. If there
is a problem with the source files generated by the plugin, set
closeWatchFileCache := com.swoval.files.FileCaches.NoCache
- closeWatchLegacyWatchLatency (sbt 1.x only) -- If using the default sbt WatchService, configures the latency of the directory watcher.
- closeWatchLegacyQueueSize (sbt 1.x only) -- If using the default sbt WatchService, configures the maximum number of watch events that will be enqueued.
- closeWatchUseDefaultWatchService (default: false, sbt 1.x only) -- Use the default sbt watch service with the MacOSXWatchService. This doesn't benefit from a number of the enhancements that the plugin makes to the ~ command, but it does make the basic watch service usable on OSX.
There are two tasks provided for debugging
- closeWatchTransitiveSources -- This shows the list of sources that the plugin is using for a
particular task. Usage:
foo/closeWatchTransitiveSources foo/compile
will show the watch sources used in the foo/compile task. Note that this can be very noisy if foo is an aggregate project. - closeWatchSourceDiff -- Shows the difference, if any, between the compilation sources generated by the default sbt source generators compared to the compilation sources generated by the plugin.
The initial implementation was based on directory-watcher, which in turn relied on takari-directoy-watcher. Thanks to @francisdb who provided lots of early feedback.
This library is licensed under the MIT license. See LICENSE for more information.