简体   繁体   中英

What's the best way using Scala and SBT to create samples for a library that can be built from the SBT CLI?

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?

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.

What you describes sounds a lot with most common use case of giter8 . Check the unfiltered examples , they are all giter8 templates. And here is a giter8 template for a giter8 project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM