Skip to content

Commit

Permalink
fix devMavenRepositories caching
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-enko committed Jun 4, 2024
1 parent 1e93ea4 commit 4838b89
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions build-logic/src/main/kotlin/dokkabuild/DevMavenPublishExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
/**
Expand All @@ -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<Set<FileSystemLocation>> =
private val devMavenRepositoriesInputFiles: Provider<List<File>> =
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,
Expand All @@ -47,15 +45,14 @@ abstract class DevMavenPublishExtension(
task.inputs.files(devMavenRepositoriesInputFiles)
.withPropertyName("devMavenPublish.devMavenRepositoriesInputFiles")
.withPathSensitivity(RELATIVE)
.ignoreEmptyDirectories()

task.dependsOn(devMavenRepositories)

if (task is JavaForkOptions) {
task.jvmArgumentProviders.systemProperty(
"devMavenRepositories",
devMavenRepositoriesInputFiles.map { paths ->
paths.joinToString(",") { it.asFile.invariantSeparatorsPath }
paths.joinToString(",") { it.absoluteFile.invariantSeparatorsPath }
},
)
}
Expand Down

0 comments on commit 4838b89

Please sign in to comment.