Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incremental ktlintCheck task fails when file is deleted #679

Closed
sam-step opened this issue Jun 20, 2023 · 1 comment · Fixed by #681
Closed

Incremental ktlintCheck task fails when file is deleted #679

sam-step opened this issue Jun 20, 2023 · 1 comment · Fixed by #681
Assignees

Comments

@sam-step
Copy link

Hi, I've noticed on v11.4.0 incremental ktlintChecks will fail when a file is deleted and another is modified.

I've been able to repro this with a test in the KtlintPluginTest suite (below). The flow seems to be:

  1. Add some files, run ktlintCheck
  2. Delete a file. ktlintCheck is up-to-date.
  3. Add or modify an existing file. ktlintCheck fails with java.io.FileNotFoundException: file_that_was_deleted.kt (No such file or directory)

Cleaning the project addresses the issue. Sample repro test is below. Looks like it passes on the v11.3.2.

    @DisplayName("Lint check should pass after file is deleted")
    @CommonTest
    fun checkAfterFileDelete(gradleVersion: GradleVersion) {
        project(gradleVersion) {
            val fileOne = "src/main/kotlin/FileOne.kt"
            createSourceFile(
                fileOne,
                """
                val foo = "bar"

                """.trimIndent()
            )

            val fileTwo = "src/main/kotlin/FileTwo.kt"
            createSourceFile(
                fileTwo,
                """
                val bar = "foo"

                """.trimIndent()
            )

            build(CHECK_PARENT_TASK_NAME) {
                assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
            }

            removeSourceFile(fileOne)
            val fileThree = "src/main/kotlin/FileThree.kt"
            createSourceFile( // Need to add or modify a source to repro file not found error.
                fileThree,
                """
                val bar = "foo"

                """.trimIndent()
            )

            build(CHECK_PARENT_TASK_NAME, "--info") { // <-- Fails, file one is not found.
                assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
            }
        }
    }

Fails with:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':runKtlintCheckOverMainSourceSet'.
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:149)
	...
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing org.jlleitschuh.gradle.ktlint.worker.KtLintWorkAction
	at org.gradle.workers.internal.DefaultWorkerExecutor$WorkItemExecution.waitForCompletion(DefaultWorkerExecutor.java:283)
	at org.gradle.internal.work.DefaultAsyncWorkTracker.lambda$waitForItemsAndGatherFailures$2(DefaultAsyncWorkTracker.java:130)
	at org.gradle.internal.Factories$1.create(Factories.java:31)
	...
Caused by: java.io.FileNotFoundException: /private/var/folders/9f/ztz6grwn0j7595f0c5l1pknw0000gq/T/junit6773990898998399332/plugin-test/src/main/kotlin/FileOne.kt (No such file or directory)
	at kotlin.io.FilesKt__FileReadWriteKt.readText(FileReadWrite.kt:125)
	at kotlin.io.FilesKt__FileReadWriteKt.readText$default(FileReadWrite.kt:125)
	at org.jlleitschuh.gradle.ktlint.worker.KtLintInvocation47.buildParams(KtLintInvocation47.kt:45)
	at org.jlleitschuh.gradle.ktlint.worker.KtLintInvocation47.invokeLint(KtLintInvocation47.kt:58)
	at org.jlleitschuh.gradle.ktlint.worker.KtLintWorkAction.execute(KtLintWorkAction.kt:108)
	at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
	...
Full Build Output
org.gradle.testkit.runner.UnexpectedBuildFailure: Unexpected build execution failure in /var/folders/9f/ztz6grwn0j7595f0c5l1pknw0000gq/T/junit6773990898998399332/plugin-test with arguments [ktlintCheck, --info, --stacktrace]

Output:
...
Starting Build
Settings evaluated using settings file '/private/var/folders/9f/ztz6grwn0j7595f0c5l1pknw0000gq/T/junit6773990898998399332/plugin-test/settings.gradle'.
Projects loaded. Root project using build file '/private/var/folders/9f/ztz6grwn0j7595f0c5l1pknw0000gq/T/junit6773990898998399332/plugin-test/build.gradle'.
Included projects: [root project 'plugin-test']

Configure project :
Evaluating root project 'plugin-test' using build file '/private/var/folders/9f/ztz6grwn0j7595f0c5l1pknw0000gq/T/junit6773990898998399332/plugin-test/build.gradle'.
The configuration detachedConfiguration1 is both resolvable and consumable. This is considered a legacy configuration and it will eventually only be possible to be one of these.
The configuration detachedConfiguration1 is both consumable and declarable. This combination is incorrect, only one of these flags should be set.
The configuration detachedConfiguration1 is both resolvable and consumable. This is considered a legacy configuration and it will eventually only be possible to be one of these.
The configuration detachedConfiguration1 is both consumable and declarable. This combination is incorrect, only one of these flags should be set.
The configuration detachedConfiguration2 is both resolvable and consumable. This is considered a legacy configuration and it will eventually only be possible to be one of these.
The configuration detachedConfiguration2 is both consumable and declarable. This combination is incorrect, only one of these flags should be set.
The configuration detachedConfiguration2 is both resolvable and consumable. This is considered a legacy configuration and it will eventually only be possible to be one of these.
The configuration detachedConfiguration2 is both consumable and declarable. This combination is incorrect, only one of these flags should be set.
The configuration :classpath is both resolvable and consumable. This is considered a legacy configuration and it will eventually only be possible to be one of these.
The configuration :classpath is both consumable and declarable. This combination is incorrect, only one of these flags should be set.
The configuration :classpath is both resolvable and consumable. This is considered a legacy configuration and it will eventually only be possible to be one of these.
The configuration :classpath is both consumable and declarable. This combination is incorrect, only one of these flags should be set.
Using Kotlin Gradle Plugin gradle76 variant
kotlin scripting plugin: created the scripting discovery configuration: kotlinScriptDef
kotlin scripting plugin: created the scripting discovery configuration: testKotlinScriptDef
All projects evaluated.
Task name matched 'ktlintCheck'
Selected primary task 'ktlintCheck' from project :
Add dependency: ktlint version 0.47.1
Add dependency: ktlint version 0.47.1
The configuration :mainSourceElements is both consumable and declarable. This combination is incorrect, only one of these flags should be set.
Tasks to be executed: [task ':loadKtlintReporters', task ':runKtlintCheckOverKotlinScripts', task ':ktlintKotlinScriptCheck', task ':runKtlintCheckOverMainSourceSet', task ':ktlintMainSourceSetCheck', task ':runKtlintCheckOverTestSourceSet', task ':ktlintTestSourceSetCheck', task ':ktlintCheck']
Tasks that were excluded: []
Resolve mutations for :loadKtlintReporters (Thread[Execution worker,5,main]) started.
:loadKtlintReporters (Thread[Execution worker,5,main]) started.

Task :loadKtlintReporters UP-TO-DATE
Caching disabled for task ':loadKtlintReporters' because:
Build cache is disabled
Skipping task ':loadKtlintReporters' as it is up-to-date.
Resolve mutations for :runKtlintCheckOverKotlinScripts (Thread[Execution worker,5,main]) started.
:runKtlintCheckOverKotlinScripts (Thread[Execution worker,5,main]) started.

Task :runKtlintCheckOverKotlinScripts NO-SOURCE
Skipping task ':runKtlintCheckOverKotlinScripts' as it has no source files and no previous output files.
Resolve mutations for :ktlintKotlinScriptCheck (Thread[Execution worker,5,main]) started.
:ktlintKotlinScriptCheck (Thread[Execution worker,5,main]) started.

Task :ktlintKotlinScriptCheck SKIPPED
Skipping task ':ktlintKotlinScriptCheck' as task onlyIf 'Task satisfies onlyIf spec' is false.
Resolve mutations for :runKtlintCheckOverMainSourceSet (Thread[Execution worker,5,main]) started.
:runKtlintCheckOverMainSourceSet (Thread[Execution worker,5,main]) started.
Resolve mutations for :runKtlintCheckOverTestSourceSet (Thread[Execution worker Thread 9,5,main]) started.
:runKtlintCheckOverTestSourceSet (Thread[Execution worker Thread 9,5,main]) started.

Task :runKtlintCheckOverTestSourceSet NO-SOURCE
Skipping task ':runKtlintCheckOverTestSourceSet' as it has no source files and no previous output files.
Resolve mutations for :ktlintTestSourceSetCheck (Thread[Execution worker Thread 9,5,main]) started.
:ktlintTestSourceSetCheck (Thread[Execution worker Thread 9,5,main]) started.

Task :ktlintTestSourceSetCheck SKIPPED
Skipping task ':ktlintTestSourceSetCheck' as task onlyIf 'Task satisfies onlyIf spec' is false.
Starting process 'Gradle Worker Daemon 2'. Working directory: ...
Successfully started process 'Gradle Worker Daemon 2'
Started Gradle worker daemon (0.289 secs) with fork options DaemonForkOptions{executable=...
This JVM does not support getting OS memory, so no OS memory status updates will be broadcast

Task :runKtlintCheckOverMainSourceSet FAILED
Caching disabled for task ':runKtlintCheckOverMainSourceSet' because:
Build cache is disabled
Task ':runKtlintCheckOverMainSourceSet' is not up-to-date because:
Input property 'source' file /private/var/folders/9f/ztz6grwn0j7595f0c5l1pknw0000gq/T/junit6773990898998399332/plugin-test/src/main/kotlin/FileOne.kt has been removed.
Input property 'source' file /private/var/folders/9f/ztz6grwn0j7595f0c5l1pknw0000gq/T/junit6773990898998399332/plugin-test/src/main/kotlin/FileThree.kt has been added.
Executing incrementally
Editorconfig files were changed: false

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':runKtlintCheckOverMainSourceSet'.

A failure occurred while executing org.jlleitschuh.gradle.ktlint.worker.KtLintWorkAction
/private/var/folders/9f/ztz6grwn0j7595f0c5l1pknw0000gq/T/junit6773990898998399332/plugin-test/src/main/kotlin/FileOne.kt (No such file or directory)

  • Try:

Run with --debug option to get more log output.
Run with --scan to get full insights.

  • Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':runKtlintCheckOverMainSourceSet'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:149)
    ...
    Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing org.jlleitschuh.gradle.ktlint.worker.KtLintWorkAction
    at org.gradle.workers.internal.DefaultWorkerExecutor$WorkItemExecution.waitForCompletion(DefaultWorkerExecutor.java:283)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.lambda$waitForItemsAndGatherFailures$2(DefaultAsyncWorkTracker.java:130)
    at org.gradle.internal.Factories$1.create(Factories.java:31)
    ...
    Caused by: java.io.FileNotFoundException: /private/var/folders/9f/ztz6grwn0j7595f0c5l1pknw0000gq/T/junit6773990898998399332/plugin-test/src/main/kotlin/FileOne.kt (No such file or directory)
    at kotlin.io.FilesKt__FileReadWriteKt.readText(FileReadWrite.kt:125)
    at kotlin.io.FilesKt__FileReadWriteKt.readText$default(FileReadWrite.kt:125)
    at org.jlleitschuh.gradle.ktlint.worker.KtLintInvocation47.buildParams(KtLintInvocation47.kt:45)
    at org.jlleitschuh.gradle.ktlint.worker.KtLintInvocation47.invokeLint(KtLintInvocation47.kt:58)
    at org.jlleitschuh.gradle.ktlint.worker.KtLintWorkAction.execute(KtLintWorkAction.kt:108)
    at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
    ...

  • Get more help at https://help.gradle.org

BUILD FAILED in 1s
2 actionable tasks: 1 executed, 1 up-to-date
Watched directory hierarchies: [/private/var/folders/9f/ztz6grwn0j7595f0c5l1pknw0000gq/T/junit6773990898998399332/plugin-test]
Stopped 1 worker daemon(s).

at org.gradle.testkit.runner.internal.DefaultGradleRunner.lambda$build$2(DefaultGradleRunner.java:264)
at org.gradle.testkit.runner.internal.DefaultGradleRunner.run(DefaultGradleRunner.java:338)
at org.gradle.testkit.runner.internal.DefaultGradleRunner.build(DefaultGradleRunner.java:262)
at org.jlleitschuh.gradle.ktlint.testdsl.TestDslKt.build(TestDsl.kt:128)
at org.jlleitschuh.gradle.ktlint.KtlintPluginTest$checkAfterFileDelete$1.invoke(KtlintPluginTest.kt:554)
at org.jlleitschuh.gradle.ktlint.KtlintPluginTest$checkAfterFileDelete$1.invoke(KtlintPluginTest.kt:521)
at org.jlleitschuh.gradle.ktlint.testdsl.TestDslKt.project(TestDsl.kt:29)
at org.jlleitschuh.gradle.ktlint.testdsl.TestDslKt.project$default(TestDsl.kt:9)
at org.jlleitschuh.gradle.ktlint.KtlintPluginTest.checkAfterFileDelete(KtlintPluginTest.kt:521)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:686)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
@wakingrufus
Copy link
Collaborator

Thanks for the failing test! This should be a quick fix. I'll work on it tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants