Read the code carefully before you run it.
fun main() {
val cache = mutableMapOf<String, Int>()
fun build(name: String, input: Int): Int {
val cached = cache[name]
return if (cached == input) {
println("$name: UP-TO-DATE")
cached
} else {
println("$name: rebuilding")
cache[name] = input
input * 2
}
}
build("moduleA", 5)
build("moduleA", 5)
build("moduleA", 7)
}
What do the three calls of build() print — which one uses the cached result?
A build system takes source code through several steps to a runnable artifact: first it is compiled, then the compiled classes are packed into an archive, and only after that can the application run. Call compile(), packageJar() and run() in main() in exactly the order a build system would execute them.
Before you get a hint: what have you tried, and where exactly are you stuck?
1. What does a build system automate according to the definition in this lesson?
2. Which point is NOT one of the typical responsibilities of a build system?