Scala SBT: Triggering an action when local dependencies change

与世无争的帅哥 提交于 2019-12-23 10:38:15

问题


In SBT, you can use the "~" mark to trigger actions whenever a source file changes. For example,

sbt> ~test

will run the unit tests whenever source changes.

Is there any good way to trigger actions whenever source changes or a local dependency changes? This would be useful when developing two projects simultaneously, where one depends on the other.

I know you can get this behavior by manually specifying a path to a file or the base project, but that's brittle, and SBT already knows where it's getting its local artifacts, so it's something I'd like to avoid.


回答1:


From the documentation for Triggered Execution, the watchSources task is where you can add additional files to be watched.

From another question, the managedClasspath task provides the part of the classpath that comes from managed dependencies.

Then, the following definition adds the managed test classpath to the files to watch for triggered execution:

watchSources <++=
  (managedClasspath in Test) map { cp => cp.files }

Define this in each project that you want to trigger on.



来源:https://stackoverflow.com/questions/15562310/scala-sbt-triggering-an-action-when-local-dependencies-change

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!