mill for dotty

mill for dotty

I was putting together some content for my upcoming scalar 2020 full stack workshop in Poland and I used dotty to whip up a short data fetch programs for the AI part.

I created the dotty program quite easily using sbt but as I was typing in some of the boilerplate for sbt, I thought this was perfect time to try mill–a scala build tool. Mill handles more than scala but I was specifically interested in using it for dotty.

I installed using coursier by running cs install mill mill-interactive. Coursier is great! Note that mill-interactive installs the interactive version, think interactive prompt, of mill. If you install mill via the shell installer, you only have one command, mill, versus via the coursier way where you get 2 commands mill and mill-i (the CLI names).

I developed the short “script” using dotty’s “main” feature and some ammonite libs that are available independent of ammonite.

Mill was fast to start and easy to put a build config together. I ran mill using mill -w download.run <arg1> <arg2> to get continuous feedback on my program.

// build.sc
import mill._, scalalib._
object download extends ScalaModule {
  def scalaVersion = "0.22.0-RC1"
  def ivyDeps = Agg(
    ivy"com.lihaoyi::requests:0.5.1".withDottyCompat(scalaVersion()),
    ivy"com.lihaoyi::ammonite-ops:2.0.4".withDottyCompat(scalaVersion()),
    ivy"org.scala-lang.modules:scala-xml_2.13:2.0.0-M1".withDottyCompat(scalaVersion()),
  )
  def scalacOptions = Seq("-indent", "-Yindent-colons", "-strict")
}

I created a .mill-version file with my mill version for repeatability. There was also a “wrapper” script I could have used that would run everywhere but automatically download mill if needed when run. No extra “project” folder was needed. The build.sbt was also simple but the above build script is straight scala and no .value constructs. mill does not yet create dotty IDE files so I wrote my own function to create .dotty-ide-artifact and .dotty-ide.json. Super easy to do although my dotty IDE files are not perfect and I ownly spent 15 minutes on the dotty ide support :-). However, dotty IDE still needs sbt.

For another dataset download, I used an ammonite script and used amm’s watch mode. mill has amm builtin so when I needed to develop the dotty IDE function, I interactively built it up as I learned the mill API, then copied “what worked” to the build file. The new dotty IDE plain function was immediately availlable to be called from the command line.

Both were easy to get working–as easy as using python. I could place the source files anywhere I wanted and I chose not to use the maven/sbt convention. so my files were in “src” and not “src/main/scala”.

We’ll cover the scripts and the run approach at my scalar 2020 workshop along with other topics around a full stack app. This was a small part of the workshop but I liked how it worked out.

One learning is the for the use case above, mill is a viable alternative to sbt. I have not run more extensive tests or tried mill for complex projects yet but I do not typically have complex builds. And yes, it was fast to start.

More to come.

Comments

Popular posts from this blog

quick note on scala.js, react hooks, monix, auth

zio environment and modules pattern: zio, scala.js, react, query management

user experience, scala.js, cats-effect, IO