Skip to content

Commit

Permalink
Fix task caching for ktfmtCheck task with multiple sourceSets (cortin…
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhauck authored May 10, 2024
1 parent 002b9f6 commit e802f87
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Please add your entries according to this format.

## Unreleased

- Fix task caching for ktfmtCheckTask when project has multiple source sets (#288)

## Version 0.18.0 _(2024-04-13)_

- Make `KtfmtCheckTask` cacheable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal constructor(workerExecutor: WorkerExecutor, layout: ProjectLayout) :
KtfmtBaseTask(workerExecutor, layout) {

@get:OutputFile
val output: Provider<RegularFile> = layout.buildDirectory.file("ktfmt/output.txt")
val output: Provider<RegularFile> = layout.buildDirectory.file("ktfmt/${this.name}/output.txt")

init {
group = KtfmtUtils.GROUP_VERIFICATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome.FAILED
import org.gradle.testkit.runner.TaskOutcome.FROM_CACHE
import org.gradle.testkit.runner.TaskOutcome.SUCCESS
import org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE
import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand All @@ -21,6 +22,7 @@ internal class KtfmtCheckTaskIntegrationTest {
@BeforeEach
fun setUp() {
File(tempDir, "src/main/java").mkdirs()
File(tempDir, "src/test/java").mkdirs()
File("src/test/resources/jvmProject").copyRecursively(tempDir)
}

Expand Down Expand Up @@ -212,6 +214,45 @@ internal class KtfmtCheckTaskIntegrationTest {
assertThat(result!!.task(":ktfmtCheckMain")?.outcome).isEqualTo(FROM_CACHE)
}

@Test
fun `check task should be up-to-date when invoked twice with multiple different sized sourceSets`() {
createTempFile(
content = "val answer = 42\n",
fileName = "SrcFile.kt",
path = "src/main/java"
)
createTempFile(
content = "val answer = 42\n",
fileName = "TestFile.kt",
path = "src/test/java"
)
createTempFile(
content = "val answer = 42\n",
fileName = "TestFile2.kt",
path = "src/test/java"
)

val firstRun: BuildResult =
GradleRunner.create()
.withProjectDir(tempDir)
.withPluginClasspath()
.withArguments("ktfmtCheck", "--info")
.build()

assertThat(firstRun.task(":ktfmtCheckMain")?.outcome).isEqualTo(SUCCESS)
assertThat(firstRun.task(":ktfmtCheckTest")?.outcome).isEqualTo(SUCCESS)

val secondRun: BuildResult =
GradleRunner.create()
.withProjectDir(tempDir)
.withPluginClasspath()
.withArguments("ktfmtCheck", "--info")
.build()

assertThat(secondRun.task(":ktfmtCheckMain")?.outcome).isEqualTo(UP_TO_DATE)
assertThat(secondRun.task(":ktfmtCheckTest")?.outcome).isEqualTo(UP_TO_DATE)
}

@Test
fun `check task is configuration cache compatible`() {
createTempFile(content = "val answer = 42\n")
Expand Down

0 comments on commit e802f87

Please sign in to comment.