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

Running clean before ktlint task results in FileNotFoundException #97

Closed
stkent opened this issue Oct 26, 2017 · 6 comments
Closed

Running clean before ktlint task results in FileNotFoundException #97

stkent opened this issue Oct 26, 2017 · 6 comments

Comments

@stkent
Copy link

stkent commented Oct 26, 2017

I have a small Kotlin project containing style violations.

I have added the ktlint Gradle task according to the instructions in the README:

configurations {
    ktlint
}

dependencies {
    ktlint "com.github.shyiko:ktlint:0.11.0"
}

task ktlint(type: JavaExec, group: "verification") {
    description = "Check Kotlin code style."
    main = "com.github.shyiko.ktlint.Main"
    classpath = configurations.ktlint
    args "src/**/*.kt"
    args "--reporter=checkstyle,output=${buildDir}/ktlint.xml"
}

When I run ./gradlew ktlint --stacktrace, I see the following output:

> Task :ktlint
/Users/stkent/dev/personal/libraries/gnag/example-kotlin/src/main/kotlin/com/btkelly/gnag/example/Main.kt:40:1: Needless blank line(s)
/Users/stkent/dev/personal/libraries/gnag/example-kotlin/src/main/kotlin/com/btkelly/gnag/example/Main.kt:42:1: Needless blank line(s)
/Users/stkent/dev/personal/libraries/gnag/example-kotlin/src/main/kotlin/com/btkelly/gnag/example/Main.kt:46:1: Needless blank line(s)


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':ktlint'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

This is expected, since ktlint appears to use a non-zero exit status to indicate that style violations are found. However, when I run ./gradlew clean ktlint --stacktrace, I see the following output:

> Task :ktlint
Exception in thread "main" java.io.FileNotFoundException: /Users/stkent/dev/personal/libraries/gnag/example-kotlin/build/ktlint.xml (No such file or directory)
        at java.io.FileOutputStream.open0(Native Method)
        at java.io.FileOutputStream.open(FileOutputStream.java:270)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:101)
        at java.io.PrintStream.<init>(PrintStream.java:208)
        at com.github.shyiko.ktlint.Main.main(Main.kt:278)


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':ktlint'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

The task still fails, but this time because of a FileNotFoundException. The file was successfully created and written to when I didn't call clean before ktlint. As far as I can tell this is a bug in ktlint?

Gradle wrapper version: 4.2.1

shyiko added a commit that referenced this issue Oct 26, 2017
@shyiko
Copy link
Collaborator

shyiko commented Oct 26, 2017

Thank you for letting me know. Fixed in 0.11.1 (Maven Central sync might take up to half an hour).

@shyiko shyiko closed this as completed Oct 26, 2017
@stkent
Copy link
Author

stkent commented Oct 26, 2017

Thanks for the speedy fix! 🏎

@deividasstr
Copy link

Getting similar error. ./gradlew ktlint --stacktrace:

~/RxObjectBoxQueryTest.kt:25:1: Unused import


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':data:ktlint'.
> Process 'command '/usr/lib/jvm/java-8-openjdk-amd64/bin/java'' finished with non-zero exit value 1

* Try:
Run with --info or --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 ':data:ktlint'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
        at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipCachedTaskExecuter.execute(SkipCachedTaskExecuter.java:103)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ResolveBuildCacheKeyExecuter.execute(ResolveBuildCacheKeyExecuter.java:66)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
        at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:256)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-openjdk-amd64/bin/java'' finished with non-zero exit value 1
        at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:389)
        at org.gradle.process.internal.DefaultJavaExecAction.execute(DefaultJavaExecAction.java:36)
        at org.gradle.api.tasks.JavaExec.exec(JavaExec.java:75)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:46)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:788)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:755)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:124)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:113)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95)
        ... 32 more


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

BUILD FAILED in 1s
4 actionable tasks: 4 executed

If I delete the unused import, build is successful.

Project level build.gradle:

configurations {
        ktlint
    }
dependencies {
        ktlint "com.github.shyiko:ktlint:0.23.1"
    }
}

module build.gradle:

task ktlint(type: JavaExec, group: "verification") {
    description = "Check Kotlin code style."
    main = "com.github.shyiko.ktlint.Main"
    classpath = configurations.ktlint
    args "src/**/*.kt"
}

check.dependsOn ktlint

task ktlintFormat(type: JavaExec, group: "formatting") {
    description = "Fix Kotlin code style deviations."
    main = "com.github.shyiko.ktlint.Main"
    classpath = configurations.ktlint
    args "-F", "src/**/*.kt"
}

Same happens on ktlintFormat.

Ubuntu 17.04, gradle 4.6, gradle plugin 3.1.2, kotlin 1.2.41

@shyiko
Copy link
Collaborator

shyiko commented May 26, 2018

@deividasstr there is no FileNotFoundException in the stacktrace you've provided. It looks fine.

@Hasiy
Copy link

Hasiy commented Dec 20, 2019

I have similar error : gradlew ktlint

Starting a Gradle Daemon, 4 incompatible and 3 stopped Daemons could not be reused, use --status for details
Configuration on demand is an incubating feature.

> Configure project :app
app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.github.bumptech.glide:compiler:4.10.0'.

> Task :app:ktlint FAILED
错误: 找不到或无法加载主类 com.github.shyiko.ktlint.Main

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:ktlint'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_192\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

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

BUILD FAILED in 15s
1 actionable task: 1 executed

my project is android project
my build.gradle:

//apply plugin: 'java'   //The 'java' plugin has been applied, but it is not compatible with the Android plugins.

configurations {
    ktlint
}

dependencies {
    ktlint "com.pinterest:ktlint:0.36.0"
}

task ktlint(type: JavaExec, group: "verification") {
    description = "Check Kotlin code style."
    classpath = configurations.ktlint
    main = "com.github.shyiko.ktlint.Main"
    args "src/**/*.kt"
    // to generate report in checkstyle format prepend following args:
    // "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml"
    // see https://github.com/shyiko/ktlint#usage for more
}
check.dependsOn ktlint

task ktlintFormat(type: JavaExec, group: "formatting") {
    description = "Fix Kotlin code style deviations."
    classpath = configurations.ktlint
    main = "com.github.shyiko.ktlint.Main"
    args "-F", "src/**/*.kt"
}

windows 10 1910, gradle 5.4.1, gradle plugin 3.5.3, kotlin 1.3.61 , Android Studio 3.5

@Tapchicoma
Copy link
Collaborator

@Hasiy ktlint finishes with non-zero exit code when tool founds any style violation and this behaviour is expected.

If in your case it still fails when there are no style violation, please open new issue.

@pinterest pinterest locked as resolved and limited conversation to collaborators Dec 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants