Skip to content

Commit

Permalink
Removed Kover artifact resolution during configuration time
Browse files Browse the repository at this point in the history
The task tree is built at the configuration stage, so getting artifacts from dependencies can lead to premature task launches, deadlocks, and performance degradation.
To eliminate resolution, it was necessary to use the Provider obtained from the corresponding file collection.

PR #386
  • Loading branch information
shanshin committed May 31, 2023
1 parent 53cb0b1 commit ea29b9f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
*/
package kotlinx.kover.gradle.plugin.test.functional.cases

import kotlinx.kover.gradle.plugin.test.functional.framework.checker.CheckerContext
import kotlinx.kover.gradle.plugin.test.functional.framework.configurator.BuildConfigurator
import kotlinx.kover.gradle.plugin.test.functional.framework.starter.ExamplesTest
import kotlinx.kover.gradle.plugin.test.functional.framework.starter.GeneratedTest
import kotlin.test.*

internal class ArtifactGenerationTests {

Expand All @@ -21,4 +24,24 @@ internal class ArtifactGenerationTests {
taskNotCalled("koverGenerateArtifact")
}
}

/**
* Check that Kover artifact files are not resolved during the task dependency tree construction process.
*
* The task tree is built at the configuration stage, so getting artifacts from dependencies can lead to premature task launches, deadlocks, and performance degradation.
*
* If a resolution is detected during configuration, the message "Configuration 'koverExternalArtifactsRelease' was resolved during configuration time" is printed.
* This message may be changed in future versions, so it's worth double-checking for this error.
*/
@ExamplesTest("android/multiproject", [":app:koverXmlReportRelease"])
fun CheckerContext.testResolveConfigurationInExecuteTime() {
assertFalse(
output.contains("Configuration 'koverExternalArtifactsRelease' was resolved during configuration time"),
"Kover Configuration was resolved during configuration time"
)
assertFalse(
output.contains("This is a build performance and scalability issue"),
"Some Configuration was resolved during configuration time, perhaps this is the Kover Configuration"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,42 @@ internal abstract class AbstractKoverReportTask(@Internal protected val tool: Co
val reportClasspath: ConfigurableFileCollection = project.objects.fileCollection()

/**
* This will cause the task to be considered out-of-date when source files have changed.
* This will cause the task to be considered out-of-date when source files of dependencies have changed.
*/
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
internal val sources: Collection<File>
get() = collectAllFiles().sources
internal val externalSources: Provider<Set<File>> = externalArtifacts.elements.map {
val content = ArtifactContent(emptySet(), emptySet(), emptySet())
content.joinWith(it.map { file -> file.asFile.parseArtifactFile() }).sources
}

/**
* This will cause the task to be considered out-of-date when coverage measurements of dependencies have changed.
*/
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
internal val externalReports: Provider<Set<File>> = externalArtifacts.elements.map {
val content = ArtifactContent(emptySet(), emptySet(), emptySet())
content.joinWith(it.map { file -> file.asFile.parseArtifactFile() }).reports
}

/**
* This will cause the task to be considered out-of-date when binary reports have changed.
* 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 reports: Collection<File>
get() = collectAllFiles().reports
internal val localSources: Provider<Set<File>> = localArtifact.map {
it.asFile.parseArtifactFile().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().reports
}

@get:Nested
val toolVariant: CoverageToolVariant = tool.variant
Expand Down

0 comments on commit ea29b9f

Please sign in to comment.