Why it matters

Compiler plugins power many libraries. Understanding shapes what's possible.

Advertisement

The architecture

Plugin: implements Plugin interface. Hooks into phases.

Load via -Xplugin flag.

Compiler plugin usagePluginextends compilerPhase hooksat specific stagesEnable in sbt-Xplugin flagWell-known plugins: kind-projector, better-monadic-for, scalafix
Plugin ecosystem.
Advertisement

How it works end to end

Common plugins: kind-projector (type lambdas), better-monadic-for (for-comprehension improvements), scalafix (linting + refactoring).

Custom plugins: for org-specific transforms.

Scala 3: uses different compiler infrastructure.