This document introduces Mill, a build tool for Scala and Java projects created by Li Haoyi as an alternative to SBT. It outlines some of SBT's limitations, describes Mill's key ideas including using a build graph and caching tasks via pure functions, and demonstrates Mill through a live coding example of building a Scala library and application with cross-compilation. Resources for learning more about Mill and build tools in general are also provided.
Live coding intro to Mill: Build Scala projects easily
1. A live-coding
introduction to Mill
Guillaume Galy
Software engineer at Fabernovel
guilgaly@gmail.com
@guilgaly
https://github.com/guilgaly
_____________________________________
/ A live-coding introduction to Mill:
| finally a build tool we can all |
understand! /
-------------------------------------
^__^
(oo)_______
(__) )/
||----w |
|| ||
2. Agenda
❖ What’s Mill?
❖ Hint: a build tool for Scala and Java, created by Li Haoyi
❖ Demo
❖ From zero, to publishing to Maven Central!
2
3. What’s wrong with SBT
❖ No, not the weird syntax…
❖ That’s fixable (and already improved a lot)
❖ The 4D grid of settings (key, task-scope, configuration and project-scope)
❖ Multi-layered, mutable, execution model
❖ Hard to understand and debug
❖ Hard to navigate in an IDE
❖ No caching by default
❖ Done on an ad-hoc basis for some tasks
3
4. The basic ideas for Mill
❖ The build graph: a directed acyclic graph
compile package
Sources ------> Bytecode ------> Release Jars
❖ That’s basically a purely functional program?
val sources = ...
val bytecode = compile(sources)
val releaseJars = package(bytecode)
❖ But also needed: caching and a way to query the build graph
❖ In Mill, provided by Tasks defined with the T macro
val sources = T.sources{ ... }
val bytecode = T{ compile(sources()) }
val releaseJars = T{ package(bytecode()) }
4
5. A couple more niceties
❖ Modularity and scoping use standard Scala language features
❖ Build modules are just objects, etc.
❖ Tasks outputs are cached and queryable as JSON
❖ Nice for integration with external tools!
❖ Each task gets a dedicated folder to write files to if needed
❖ Then return a hash (for cache invalidation) + file path (for the next task to read only)
❖ Bonus point: the mill command has relatively little fixed overhead
5
6. Live demo
❖ Multi-module build (library + app)
❖ Scala versions cross-compilation
❖ Scala JS/JVM cross-compilation
❖ Publishing the library
https://github.com/guilgaly/mill-demo-scalaio2019
_______________________________
/ Let's write a cowsay
| implementation in Scala, with |
Mill as our build tool. /
-------------------------------
__
/
| |
@ @
| |
|| |/
|| ||
|_/|
___/
6