From a7a79dc1ab0192137036515c415e513e4463d612 Mon Sep 17 00:00:00 2001 From: Ben Liblit Date: Mon, 3 Jul 2023 18:40:34 -0400 Subject: [PATCH] Avoid using task extensions at task execution time Apparently the Gradle configuration cache does not permit accessing task extensions at task execution time. Instead, use task input properties to store little bits of information that (1) influence a task's own behavior and also (2) are needed in order to configure *other* tasks' behaviors. --- cast/java/test/data/build.gradle.kts | 10 +++++++--- core/build.gradle.kts | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cast/java/test/data/build.gradle.kts b/cast/java/test/data/build.gradle.kts index 8bf1cae4d5..b773d3ea47 100644 --- a/cast/java/test/data/build.gradle.kts +++ b/cast/java/test/data/build.gradle.kts @@ -45,11 +45,15 @@ val downloadJLex by tasks.registering(VerifiedDownload::class) { src = URL("https://www.cs.princeton.edu/~appel/modern/java/JLex/current/Main.java") checksum = "fe0cff5db3e2f0f5d67a153cf6c783af" - val downloadedSourceDir by extra(layout.buildDirectory.dir(name)) - dest = downloadedSourceDir.map { it.file("JLex/Main.java") } + val downloadedSourceDir = layout.buildDirectory.dir(name).map(Directory::toString) + inputs.property("downloadedSourceDir", downloadedSourceDir) + dest = layout.buildDirectory.dir(name).map { it.file("JLex/Main.java") } } -sourceSets.test.get().java.srcDir(downloadJLex.map { it.extra["downloadedSourceDir"]!! }) +sourceSets.test + .get() + .java + .srcDir(downloadJLex.map { it.inputs.properties["downloadedSourceDir"]!! }) //////////////////////////////////////////////////////////////////////// // diff --git a/core/build.gradle.kts b/core/build.gradle.kts index ea2738060b..54392228f0 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -172,7 +172,8 @@ val buildKawaTestJar by val downloadBcel by tasks.registering(VerifiedDownload::class) { - val basename by extra("bcel-5.2") + val basename = "bcel-5.2" + inputs.property("basename", basename) val archive = "${basename}.tar.gz" src = URL("https://archive.apache.org/dist/jakarta/bcel/binaries/$archive") dest = project.layout.buildDirectory.file(archive) @@ -182,7 +183,7 @@ val downloadBcel by val extractBcel by tasks.registering { - val basename = downloadBcel.map { it.extra["basename"] as String } + val basename = downloadBcel.map { it.inputs.properties["basename"] as String } val jarFile = basename.flatMap { layout.buildDirectory.file("$name/${it}.jar") } inputs.files(downloadBcel.map { it.outputs.files }) outputs.file(jarFile)