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?
Share
You can make a sub-project in SBT that depends on your main project. This allows you to build your library without compiling the examples, but when you need to compile the examples, you can do so with a separate command that will build the library if it needs to.
A good example is with Twitter’s Finagle project. You can see they have a sub-project “finagle-example” which contains a bunch of examples. Take a look at /project/Build.scala to see how they define all the sub-projects. You should be able to do the same with yours.