sbt

Notes on using Dotty (Scala 3), SBT, and VS Code together

As a note to self, here are some ways to work with Dotty (Scala 3), SBT, and VS Code (Visual Studio Code).

Create a Dotty project:

sbt new lampepfl/dotty.g8

Launch VS Code inside that project directory, with Dotty support:

sbt launchIDE

Start SBT as usual:

sbt

Those notes are just a reminder for myself, but hopefully they’ll also help others work with Dotty, SBT, and VS Code.

A Scala “functional programming style” To-Do List application

Back when I was writing Functional Programming, Simplified I started to write a little Scala/FP “To-Do List” application that you can run from the command line. For reasons I don’t remember, I decided not to include it in the book, and forgot about it until I recently started using GraalVM (what I call Graal).

Graal includes a native image feature lets you compile JVM classes and JAR files into native executables, so as I thought about things I can make faster, I was reminded of the To-Do List app and thought about how cool it would be if it started instantaneously. So I found the old project, blew the dust off of it (updated all of its dependencies), and made a few additions so I could create (a) a single, executable JAR file with sbt-assembly, and (b) a native executable with Graal.

How to create a Scala 3 (Dotty) project with SBT

I can never remember how to create a Scala 3 (Dotty) project with SBT (in early 2019), so:

# create a new Dotty project
sbt new lampepfl/dotty.g8

# create a dotty project that cross compiles with scala 2
sbt new lampepfl/dotty-cross.g8

# start a dotty reply from within your sbt project
$ sbt

> console
scala> _

Here’s what an example interaction looks like — include SBT renaming my directory name to all lowercase, which brings me no joy:

Bloop’s compiler performance is ~29% faster than SBT (on at least one project)

I had read that Bloop was faster than Scala compiler tools like scalac and fsc, so I wondered if it was faster than SBT, and if so, how much faster. So I downloaded Eric Torreborre’s specs2 source code, which has 880 source code files, and compiled the entire project with both SBT and Bloop.

SBT performance

To test SBT’s speed, I ran all the commands from inside the SBT command prompt, which I usually do anyway to avoid the SBT/JVM startup lag time. I also ran clean and compile several times before recording SBT’s speed, because I thought that would be a better reflection of real-world usage and performance. I ran the tests four times, and the average time with SBT was 49 seconds, and that was very consistent, always coming in between 48 and 50 seconds.

Bloop performance

Using Jenkins with Scala, ScalaTest, SBT, and Git

I’ve used Jenkins before, but hadn’t used it in a while, so when I got it running with Scala, SBT, ScalaTest, and Git, I made some notes about how to configure it. You can get Jenkins going with Docker, but I just got Jenkins running by starting its WAR file like this:

java -jar jenkins.war

Jenkins with Scala, SBT, ScalaTest, and Git

My notes on getting everything up and running are a little cryptic, but if you have a little experience with Jenkins I hope they’ll make sense. Here they are:

Jenkins tutorials (Jenkins, Docker, Scala, SBT, Java, Maven, and Git)

As a brief note to self, these were the two best Jenkins tutorials I found in early 2019:

The first one shows how to run Jenkins with Docker, and the second one shows how to build a Java/Maven/Git project.

This tutorial on how to use Jenkins with Scala and SBT was also helpful:

ScalaCheck custom generator examples

Table of Contents1 - Custom generators2 - Built-in ScalaCheck generators3 - How to use ScalaCheck generators4 - More ScalaCheck generators

Writing custom generators for ScalaCheck can be one of the more difficult and/or time-consuming parts of using it. As a result I thought I’d start putting together a list of generators that I have written or seen elsewhere. Unfortunately I can’t credit all the ones I’ve seen in other places because I google’d and copied them many moons ago, but I’ll give credit/attribution to all the ones I can.

Back to top

Custom generators

This is a combination of generators I wrote, and some that I copied from other places and may have modified a little: