Create Your Scala Project Today
I created a base Scala application repository so that I didn’t have to do it every time I started a new project. Maybe you’ll find it useful too!
Find it here: https://github.com/robinske/scala-base-app
Every Scala project follows a similar directory structure. It’s not required to format this way, but it’s standard and one of the subset of ways that SBT supports. For more information on the directory structure, see the SBT docs.
What’s with the “tld/domain” nested directories?
This is a convention taken from Maven/Java. The class path isn’t as important for Scala code, but many people still follow this convention. Use the tld of your site (company, organization, project, or personal).
- My personal site: http://krobinson.me - I use this for any side project I work on initially, even if it might have its own site someday or I’m not deploying it to my personal site.
- My directory structure:
The following directory structure also works if you don’t want to include the organization:
Things you’ll need to change:
- ‘name’ in build.sbt - make it your own project name
- The names of the folders in your directory structure (see above)
To set the sbt version, update
Run SBT (
scala-base-app $ sbt) from the top directory, or you’re gonna have a bad time.
Useful SBT commands:
These are useful once you’re already inside of sbt (after you’ve run
$ sbt from the top level of this directory)
||runs the main class (In this project,
||runs all the tests|
||runs a subset of tests based on what code has changed|
||compiles the code|
||reloads changes to the
Note: prepend any of the above with
~ for re-evaluation. i.e.
~test-quick will rerun the subset of affected tests every time code is changed.
This is an intentionally brief overview and a quick start to a Scala project. Here are some more resources to expand your Scala knowledge:
If you’re new to Scala and have no idea where to start, here are some ideas to expand this (forked or cloned) project for your own learning:
- Take user input for the date
- Print different formats
- Turn this into a web-application
- Consume an API (http://www.timeapi.org/)
- As always, write more tests!