Skip to content

Commit

Permalink
Fixed reusing of configuration cache
Browse files Browse the repository at this point in the history
Due to the fact that a file was used as task input, it was placed in the configuration cache as entry, and changing this file causes the cache invalidation.

Problem in line `localArtifact.set(variant.artifactGenTask.flatMap { task -> task.artifactFile })`.
flatMap function behaves strangely enough with the configuration cache, see also gradle/gradle#25645

Fixes #646

PR #648
  • Loading branch information
shanshin authored Jun 27, 2024
1 parent 8cee8cb commit 67c7836
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ internal class ConfigurationCacheTests {
"koverVerify",
"--configuration-cache",
)

// test reusing configuration cache
run(
"build",
"koverXmlReport",
"koverHtmlReport",
"koverVerify",
"--configuration-cache",
) {
output.match {
assertContains("Reusing configuration cache.")
}
}
}

@GeneratedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ internal fun prepare(project: Project): KoverContext {
asBucket()
}

// Project always consumes its own artifacts
project.dependencies.add(KOVER_DEPENDENCY_NAME, project)

val projectExtension = project.extensions.create<KoverProjectExtensionImpl>(
KOVER_PROJECT_EXTENSION_NAME,
project.objects,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,8 @@ internal class VariantReportsSet(

private fun <T : AbstractKoverReportTask> TaskProvider<T>.assign(variant: AbstractVariantArtifacts) {
configure {
dependsOn(variant.artifactGenTask)
dependsOn(variant.consumerConfiguration)

localArtifact.set(variant.artifactGenTask.flatMap { task -> task.artifactFile })
externalArtifacts.from(variant.consumerConfiguration)
artifacts.from(variant.consumerConfiguration)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ internal abstract class AbstractKoverReportTask : DefaultTask() {
@get:Internal
abstract val variantName: String

@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val localArtifact: RegularFileProperty

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val externalArtifacts: ConfigurableFileCollection
abstract val artifacts: ConfigurableFileCollection

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
Expand All @@ -38,7 +34,7 @@ internal abstract class AbstractKoverReportTask : DefaultTask() {
*/
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
internal val externalSources: Provider<Set<File>> = externalArtifacts.elements.map {
internal val sources: Provider<Set<File>> = artifacts.elements.map {
val content = ArtifactContent.Empty
content.joinWith(it.map { file -> file.asFile.parseArtifactFile(rootDir).filterProjectSources() }).sources
}
Expand All @@ -48,29 +44,11 @@ internal abstract class AbstractKoverReportTask : DefaultTask() {
*/
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
internal val externalReports: Provider<Set<File>> = externalArtifacts.elements.map {
internal val reports: Provider<Set<File>> = artifacts.elements.map {
val content = ArtifactContent.Empty
content.joinWith(it.map { file -> file.asFile.parseArtifactFile(rootDir).filterProjectSources() }).reports
}

/**
* This will cause the task to be considered out-of-date when source files of this project have changed.
*/
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
internal val localSources: Provider<Set<File>> = localArtifact.map {
it.asFile.parseArtifactFile(rootDir).filterProjectSources().sources
}

/**
* This will cause the task to be considered out-of-date when coverage measurements of this project have changed.
*/
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
internal val localReports: Provider<Set<File>> = localArtifact.map {
it.asFile.parseArtifactFile(rootDir).filterProjectSources().reports
}

@get:Nested
val toolVariant: CoverageToolVariant
get() = tool.get().variant
Expand All @@ -95,8 +73,8 @@ internal abstract class AbstractKoverReportTask : DefaultTask() {
}

private fun collectAllFiles(): ArtifactContent {
val local = localArtifact.get().asFile.parseArtifactFile(rootDir).filterProjectSources()
return local.joinWith(externalArtifacts.files.map { it.parseArtifactFile(rootDir).filterProjectSources() }).existing()
val local = ArtifactContent(projectPath, emptySet(), emptySet(), emptySet())
return local.joinWith(artifacts.files.map { it.parseArtifactFile(rootDir).filterProjectSources() }).existing()
}

private fun ArtifactContent.filterProjectSources(): ArtifactContent {
Expand Down

0 comments on commit 67c7836

Please sign in to comment.