1. Overview

In this tutorial, we’ll see how we can create a new Scala sbt project using the Giter8 command line tool.

2. What Is Giter8?

Giter8 is a command line tool that uses templates to generate a set of files and directories. This makes it a great tool for creating new projects with a standard structure.

Interestingly, Giter8 is also implemented in Scala.  

3. Using Giter8 With sbt

Giter8 has an sbt integration. We can use it through the sbt new command:

$ sbt new scala/scala-seed.g8

This produces a new project with the following structure:

$ tree scala-seed-project/
scala-seed-project/
├── build.sbt
├── project
│   ├── Dependencies.scala
│   └── build.properties
└── src
    ├── main
    │   └── scala
    │       └── example
    │           └── Hello.scala
    └── test
        └── scala
            └── example
                └── HelloSpec.scala

8 directories, 5 files

We can use the generated structure as a starting point for a new Scala project.

We used one of the many available project templates in the previous example. The Giter8 wiki contains a list of other templates that are available. There are templates for a number of different projects, including for the Play framework, Akka, and Spark.

Furthermore, we can create our own templates for our own projects.

4.  Conclusion

In this article, we saw how to create a new Scala sbt project using an existing Giter8 template. The Giter8 command line tool lets us quickly bootstrap a new sbt project from scratch with the correct file structure.


« 上一篇: Scala 函数式编程
» 下一篇: Cats 中的 Writer Monad