Scala for Node.js developers — Step 2: Project skeleton

Update: Since version 0.13.13 of sbt this is how you create new project skeleton:

sbt new sbt/scala-seed.g8

I left the rest of article as it can be of use for somebody to describe how the structure looks like.

In first step I “described” how to install scala and sbt on Ubuntu 16.04. It’s time to write some code but what’s the structure of non-framework related app? That’s interesting question, there’s no skeleton building cli or anything. You need to craft it every single time (yeah.. I couldn’t believe as well) and it’s more than “lib directory” to create.

Here’s how it should look like:

.
|-- build.sbt
|-- project
|-- src
| |-- main
| | |-- java
| | |-- resources
| | |-- scala
| |-- test
| |-- java
| |-- resources
| |-- scala
|-- target

What’s going one here:

  • build.sbt — think about it as programmable package.json file in Node.js
  • project — contains project related files, there are some files there when you start to play with frameworks like “Play Framework” — sbt will create it
  • src — is your new closest friend to be precise src/main/scala. This is the place where you should put your scala files and tests in src/test/scala.
  • target — directory created by sbt with all compiled code, I didn’t even look into it

To generate it run following:

mkdir myFirstScalaProject
cd myFirstScalaProject
mkdir -p src/{main,test}/{java,resources,scala}
echo 'name := "myFirstScalaProject"
version := "1.0"
scalaVersion := "2.12.1"' > build.sbt

This should allow you to start writing code which I will discuss in next chapter.