3

I'm creating a library in Scala and would like to include some usage samples with the source. However, I don't want those samples to reside within the main source directory (since they're not a part of the library proper), nor do I want them to be built by default when you build the library. But I would like to be able to do something like "build-samples" from the SBT prompt. What's the most straightforward way to do this?

4

2 回答 2

5

您可以在 SBT 中创建一个依赖于您的主项目的子项目。这允许您在不编译示例的情况下构建您的库,但是当您需要编译示例时,您可以使用单独的命令来执行此操作,该命令将在需要时构建库。

Twitter 的Finagle项目就是一个很好的例子。您可以看到他们有一个子项目“finagle-example”,其中包含一堆示例。查看/project/Build.scala以了解它们如何定义所有子项目。你应该可以对你的做同样的事情。

于 2012-10-08T01:14:21.917 回答
0

您所描述的内容与giter8的最常见用例听起来很多。检查未过滤的示例,它们都是 giter8 模板。这是一个giter8 项目的giter8 模板

于 2012-10-08T01:45:03.737 回答