Skip to content

Commit

Permalink
Avoid using task extensions at task execution time
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
liblit committed Jul 3, 2023
1 parent 6dff272 commit a7a79dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 7 additions & 3 deletions cast/java/test/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]!! })

////////////////////////////////////////////////////////////////////////
//
Expand Down
5 changes: 3 additions & 2 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit a7a79dc

Please sign in to comment.