Don't fail after first codestyle violation
See original GitHub issueI tried out spotless today for the first time on one of our Kotlin projects and thus used the ktlint plugin.
It seems to work quite well so far, however spotlessCheck
always fails right after finding the first codestyle violation while ktlint
(when directly run on the codebase) lists all violations in a neat list.
I also tried to apply various different ktlint reporters (like the checkstyle one), but the result always seems to be the same - failure after the first violation (and in this case also no checkstyle XML is generated).
Long story short: can I force spotless (or the ktlint plugin, if that’s the culprit) to continue its checks after it found a violation so that I can see all violations at a glance (and if possible without that stacktrace which causes the need for a lot of scrolling to find the error)?
Config looks like this:
spotless {
kotlin {
ktlint().userData(['android': 'true', 'color': 'true', 'reporter': 'checkstyle'])
target '**/*.kt'
}
}
Sample output:
./gradlew :app:spotlessCheck
> Configure project :app
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
> Task :app:spotlessKotlin FAILED
Step 'ktlint' found problem in 'app/src/main/java/my/app/package/repository/game/MatchItemMapper.kt':
Error on line: 27, column: 1
Exceeded max line length (100)
java.lang.AssertionError: Error on line: 27, column: 1
Exceeded max line length (100)
at com.diffplug.spotless.kotlin.KtLintStep$State.lambda$createFormat$0(KtLintStep.java:114)
at com.sun.proxy.$Proxy96.invoke(Unknown Source)
at com.github.shyiko.ktlint.core.KtLint$format$2$1.invoke(KtLint.kt:354)
at com.github.shyiko.ktlint.core.KtLint$format$2$1.invoke(KtLint.kt:36)
at com.github.shyiko.ktlint.ruleset.standard.MaxLineLengthRule.visit(MaxLineLengthRule.kt:69)
at com.github.shyiko.ktlint.core.KtLint$format$2.invoke(KtLint.kt:352)
at com.github.shyiko.ktlint.core.KtLint$format$2.invoke(KtLint.kt:36)
at com.github.shyiko.ktlint.core.KtLint$visitor$2$3.invoke(KtLint.kt:216)
at com.github.shyiko.ktlint.core.KtLint$visitor$2$3.invoke(KtLint.kt:36)
at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:489)
at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:490)
at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:490)
at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:490)
at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:490)
at com.github.shyiko.ktlint.core.KtLint.access$visit(KtLint.kt:36)
at com.github.shyiko.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:214)
at com.github.shyiko.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:36)
at com.github.shyiko.ktlint.core.KtLint.format(KtLint.kt:347)
at com.github.shyiko.ktlint.core.KtLint.format(KtLint.kt:277)
at com.diffplug.spotless.kotlin.KtLintStep$State.lambda$createFormat$1(KtLintStep.java:128)
at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:78)
at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:76)
at com.diffplug.spotless.Formatter.compute(Formatter.java:230)
at com.diffplug.spotless.Formatter.isClean(Formatter.java:167)
at com.diffplug.gradle.spotless.SpotlessTask.check(SpotlessTask.java:263)
at com.diffplug.gradle.spotless.SpotlessTask.performAction(SpotlessTask.java:205)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
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.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)
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.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
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)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:spotlessKotlin'.
> Error on line: 27, column: 1
Exceeded max line length (100)
* 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 0s
1 actionable task: 1 executed
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:9 (4 by maintainers)
Top GitHub Comments
@JLLeitschuh Haha, yeah, I saw that. 😉
The main reason for switching to ktlint-gradle is that I like to keep the toolchain as lean as possible and we really only want the checks in ktlint for now. No other reasons at the moment. 😃
I will make sure to close the issue after confirming that
--continue
works.This comment made me chuckle as I’m a maintainer on both projects. If you don’t mind me asking, were there any other reasons why you chose
ktlint-gradle
overspotless
?Also, if this issue is truly resolved for you, please close the issue when you’ve confirmed it’s fixed.