From 4838b8910699d0881a082c99161acea03d1e8d95 Mon Sep 17 00:00:00 2001 From: Adam Semenenko <152864218+adam-enko@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:15:32 +0200 Subject: [PATCH] fix devMavenRepositories caching --- .../dokkabuild/DevMavenPublishExtension.kt | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/build-logic/src/main/kotlin/dokkabuild/DevMavenPublishExtension.kt b/build-logic/src/main/kotlin/dokkabuild/DevMavenPublishExtension.kt index 8076318c53..a86724ca88 100644 --- a/build-logic/src/main/kotlin/dokkabuild/DevMavenPublishExtension.kt +++ b/build-logic/src/main/kotlin/dokkabuild/DevMavenPublishExtension.kt @@ -6,10 +6,10 @@ package dokkabuild import dokkabuild.utils.systemProperty import org.gradle.api.Task import org.gradle.api.file.FileCollection -import org.gradle.api.file.FileSystemLocation import org.gradle.api.provider.Provider import org.gradle.api.tasks.PathSensitivity.RELATIVE import org.gradle.process.JavaForkOptions +import java.io.File abstract class DevMavenPublishExtension( /** @@ -23,21 +23,19 @@ abstract class DevMavenPublishExtension( /** * Files suitable for registering as a task input (as in, the files are reproducible-build compatible). */ - private val devMavenRepositoriesInputFiles: Provider> = + private val devMavenRepositoriesInputFiles: Provider> = devMavenRepositories + // Convert to a FileTree, so we can filter out files. + .asFileTree + // Exclude Maven Metadata files because they contain timestamps, meaning tasks that use + // devMavenRepositories as an input will never be up-to-date. + // The Gradle Module Metadata contains the same information (and more), + // so the Maven metadata is redundant. + .matching { exclude("**/maven-metadata*.xml") } + // FileTrees have an unstable order (even on the same machine), which means Gradle up-to-date checks fail. + // So, manually sort the files so that Gradle can cache the task. .elements - .map { files -> - files - .filterNot { - // Exclude Maven Metadata files because they contain timestamps, meaning tasks that use - // devMavenRepositories as an input will never be up-to-date. - // The Gradle Module Metadata contains the same information (and more), - // so the Maven metadata is redundant. - it.asFile.name.run { startsWith("maven-metadata") && endsWith(".xml") } - } - // sort the elements to ensure that the contents are reproducible - .toSortedSet { a, b -> a.asFile.compareTo(b.asFile) } - } + .map { files -> files.map { it.asFile }.sorted() } /** * Configures [task] to register [devMavenRepositories] as a task input, @@ -47,7 +45,6 @@ abstract class DevMavenPublishExtension( task.inputs.files(devMavenRepositoriesInputFiles) .withPropertyName("devMavenPublish.devMavenRepositoriesInputFiles") .withPathSensitivity(RELATIVE) - .ignoreEmptyDirectories() task.dependsOn(devMavenRepositories) @@ -55,7 +52,7 @@ abstract class DevMavenPublishExtension( task.jvmArgumentProviders.systemProperty( "devMavenRepositories", devMavenRepositoriesInputFiles.map { paths -> - paths.joinToString(",") { it.asFile.invariantSeparatorsPath } + paths.joinToString(",") { it.absoluteFile.invariantSeparatorsPath } }, ) }