Skip to content

Commit 67c7836

Browse files
authored
Fixed reusing of configuration cache
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
1 parent 8cee8cb commit 67c7836

File tree

4 files changed

+22
-31
lines changed

4 files changed

+22
-31
lines changed

Diff for: kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/ConfigurationCacheTests.kt

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ internal class ConfigurationCacheTests {
2929
"koverVerify",
3030
"--configuration-cache",
3131
)
32+
33+
// test reusing configuration cache
34+
run(
35+
"build",
36+
"koverXmlReport",
37+
"koverHtmlReport",
38+
"koverVerify",
39+
"--configuration-cache",
40+
) {
41+
output.match {
42+
assertContains("Reusing configuration cache.")
43+
}
44+
}
3245
}
3346

3447
@GeneratedTest

Diff for: kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/PrepareKover.kt

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ internal fun prepare(project: Project): KoverContext {
2323
asBucket()
2424
}
2525

26+
// Project always consumes its own artifacts
27+
project.dependencies.add(KOVER_DEPENDENCY_NAME, project)
28+
2629
val projectExtension = project.extensions.create<KoverProjectExtensionImpl>(
2730
KOVER_PROJECT_EXTENSION_NAME,
2831
project.objects,

Diff for: kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/tasks/VariantReportsSet.kt

+1-4
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,8 @@ internal class VariantReportsSet(
192192

193193
private fun <T : AbstractKoverReportTask> TaskProvider<T>.assign(variant: AbstractVariantArtifacts) {
194194
configure {
195-
dependsOn(variant.artifactGenTask)
196195
dependsOn(variant.consumerConfiguration)
197-
198-
localArtifact.set(variant.artifactGenTask.flatMap { task -> task.artifactFile })
199-
externalArtifacts.from(variant.consumerConfiguration)
196+
artifacts.from(variant.consumerConfiguration)
200197
}
201198
}
202199

Diff for: kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tasks/reports/AbstractKoverReportTask.kt

+5-27
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ internal abstract class AbstractKoverReportTask : DefaultTask() {
2121
@get:Internal
2222
abstract val variantName: String
2323

24-
@get:InputFile
25-
@get:PathSensitive(PathSensitivity.RELATIVE)
26-
abstract val localArtifact: RegularFileProperty
27-
2824
@get:InputFiles
2925
@get:PathSensitive(PathSensitivity.RELATIVE)
30-
abstract val externalArtifacts: ConfigurableFileCollection
26+
abstract val artifacts: ConfigurableFileCollection
3127

3228
@get:InputFiles
3329
@get:PathSensitive(PathSensitivity.RELATIVE)
@@ -38,7 +34,7 @@ internal abstract class AbstractKoverReportTask : DefaultTask() {
3834
*/
3935
@get:InputFiles
4036
@get:PathSensitive(PathSensitivity.RELATIVE)
41-
internal val externalSources: Provider<Set<File>> = externalArtifacts.elements.map {
37+
internal val sources: Provider<Set<File>> = artifacts.elements.map {
4238
val content = ArtifactContent.Empty
4339
content.joinWith(it.map { file -> file.asFile.parseArtifactFile(rootDir).filterProjectSources() }).sources
4440
}
@@ -48,29 +44,11 @@ internal abstract class AbstractKoverReportTask : DefaultTask() {
4844
*/
4945
@get:InputFiles
5046
@get:PathSensitive(PathSensitivity.RELATIVE)
51-
internal val externalReports: Provider<Set<File>> = externalArtifacts.elements.map {
47+
internal val reports: Provider<Set<File>> = artifacts.elements.map {
5248
val content = ArtifactContent.Empty
5349
content.joinWith(it.map { file -> file.asFile.parseArtifactFile(rootDir).filterProjectSources() }).reports
5450
}
5551

56-
/**
57-
* This will cause the task to be considered out-of-date when source files of this project have changed.
58-
*/
59-
@get:InputFiles
60-
@get:PathSensitive(PathSensitivity.RELATIVE)
61-
internal val localSources: Provider<Set<File>> = localArtifact.map {
62-
it.asFile.parseArtifactFile(rootDir).filterProjectSources().sources
63-
}
64-
65-
/**
66-
* This will cause the task to be considered out-of-date when coverage measurements of this project have changed.
67-
*/
68-
@get:InputFiles
69-
@get:PathSensitive(PathSensitivity.RELATIVE)
70-
internal val localReports: Provider<Set<File>> = localArtifact.map {
71-
it.asFile.parseArtifactFile(rootDir).filterProjectSources().reports
72-
}
73-
7452
@get:Nested
7553
val toolVariant: CoverageToolVariant
7654
get() = tool.get().variant
@@ -95,8 +73,8 @@ internal abstract class AbstractKoverReportTask : DefaultTask() {
9573
}
9674

9775
private fun collectAllFiles(): ArtifactContent {
98-
val local = localArtifact.get().asFile.parseArtifactFile(rootDir).filterProjectSources()
99-
return local.joinWith(externalArtifacts.files.map { it.parseArtifactFile(rootDir).filterProjectSources() }).existing()
76+
val local = ArtifactContent(projectPath, emptySet(), emptySet(), emptySet())
77+
return local.joinWith(artifacts.files.map { it.parseArtifactFile(rootDir).filterProjectSources() }).existing()
10078
}
10179

10280
private fun ArtifactContent.filterProjectSources(): ArtifactContent {

0 commit comments

Comments
 (0)