Skip to content

Conversation

eed3si9n
Copy link
Member

@eed3si9n eed3si9n commented Jun 10, 2025

This flips the default := operation to the cached task. For example, the following task would be cached:

val someKey = taskKey[String]("something")

someKey := {
  name.value + version.value + "!"
}

Per-task-key opt-out

To opt out of the cache at the key level, use @cacheLevel(include = Array.empty).

@cacheLevel(include = Array.empty)
val someKey = taskKey[String]("something")

// someKey will not be cached
someKey := {
  name.value + somethingUncachable.value + "!"
}

Per-task opt-out

To opt out of the cache individually, use Def.uncached(...).

val someKey = taskKey[String]("something")

someKey := Def.uncached {
  name.value + somethingUncachable.value + "!"
}

Build-wide opt-out

Add the following to project/plugins.sbt:

Compile / scalacOptions += "-Xmacro-settings:sbt:no-default-task-cache"

Note about side effects

Any tasks involving files require careful consideration to capture the side effects.
See https://www.scala-sbt.org/2.x/docs/en/concepts/caching.html#caching-files for details.

@eed3si9n eed3si9n force-pushed the wip/cached-by-default branch 5 times, most recently from 7845f5f to 0186b1b Compare June 15, 2025 08:38
@eed3si9n eed3si9n force-pushed the wip/cached-by-default branch from 62ba47a to 6080cce Compare June 20, 2025 14:29
This flips the default `:=` operation to the cached task.
To opt out of the cache, use `Def.uncached(...)` or
mark the key with `@cacheLevel(include = Array.empty)`
@eed3si9n eed3si9n force-pushed the wip/cached-by-default branch from 41b927e to 6a7b56a Compare June 20, 2025 23:55
@eed3si9n eed3si9n marked this pull request as ready for review June 20, 2025 23:55
@eed3si9n eed3si9n merged commit 1a06f29 into sbt:develop Jun 21, 2025
12 checks passed
@eed3si9n eed3si9n deleted the wip/cached-by-default branch June 21, 2025 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant