Revert configuration cache (#1659)

This reverts the commits that enabled Gradle's configuration cache
feature.

IMO: this feature is too hard to use. We don't know if a task is valid
for the configuration cache until it runs, and it's very hard to tell if
something is safe when authoring Gradle code.
For example, our publish tasks are currently failing; I don't know how I
would fix this without running the publish task again on my dev machine.

Also, some of our build scripts become more brittle because of this; for
example, see
https://github.com/apple/pkl/blob/bb07589eae0b3195a589559a3245cbc12c29b394/build-logic/src/main/kotlin/BuildInfo.kt#L291-L296
This commit is contained in:
Daniel Chao
2026-06-05 23:31:40 +00:00
committed by GitHub
parent bb07589eae
commit 1cc20b611f
21 changed files with 180 additions and 307 deletions
@@ -15,10 +15,8 @@
*/
import com.diffplug.spotless.FormatterFunc
import com.diffplug.spotless.FormatterStep
import java.io.File
import java.io.Serial
import java.io.Serializable
import java.lang.reflect.Method
import java.net.URLClassLoader
import org.gradle.api.artifacts.Configuration
@@ -28,45 +26,31 @@ class PklFormatterStep(@Transient private val configuration: Configuration) : Se
}
fun create(): FormatterStep {
val files = configuration.files.toList()
return FormatterStep.createLazy(
"pkl",
{ PklFormatterState(files) },
{ PklFormatterFunc(it.files) },
{ PklFormatterStep(configuration) },
{ PklFormatterFunc(configuration) },
)
}
}
data class PklFormatterState(val files: List<File>) : Serializable {
companion object {
@Serial private const val serialVersionUID: Long = 1L
}
}
class PklFormatterFunc(private val files: List<File>) : FormatterFunc, Serializable {
class PklFormatterFunc(@Transient private val configuration: Configuration) :
FormatterFunc, Serializable {
companion object {
@Serial private const val serialVersionUID: Long = 1L
}
@delegate:Transient
private val classLoader: URLClassLoader by lazy {
val urls = files.map { it.toURI().toURL() }
private val classLoader by lazy {
val urls = configuration.files.map { it.toURI().toURL() }
// Use the platform classloader as parent to isolate from Gradle's classloader
URLClassLoader(urls.toTypedArray(), ClassLoader.getPlatformClassLoader())
}
@delegate:Transient
private val formatterClass: Class<*> by lazy {
classLoader.loadClass("org.pkl.formatter.Formatter")
}
private val formatterClass by lazy { classLoader.loadClass("org.pkl.formatter.Formatter") }
@delegate:Transient
private val formatMethod: Method by lazy {
formatterClass.getMethod("format", String::class.java)
}
private val formatMethod by lazy { formatterClass.getMethod("format", String::class.java) }
@delegate:Transient
private val formatterInstance: Any by lazy { formatterClass.getConstructor().newInstance() }
private val formatterInstance by lazy { formatterClass.getConstructor().newInstance() }
override fun apply(input: String): String {
return formatMethod(formatterInstance, input) as String