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

Error from spotless after running a clean before ktlint linting #159

Closed
JLLeitschuh opened this issue Oct 25, 2017 · 11 comments
Closed

Error from spotless after running a clean before ktlint linting #159

JLLeitschuh opened this issue Oct 25, 2017 · 11 comments
Labels

Comments

@JLLeitschuh
Copy link
Member

Running a ./gradlew clean spotlessCheck or ./gradlew clean spotlessApply sometimes results in an error like this:

Step 'ktlint' found problem in 'src/main/kotlin/com/plexxi/fitting/api/ComputationalInterfaces.kt':
null
java.lang.reflect.InvocationTargetException
        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 com.diffplug.spotless.kotlin.KtLintStep$State.createFormat(KtLintStep.java:85)
        at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:76)
        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:216)
        at com.diffplug.gradle.spotless.SpotlessTask.performAction(SpotlessTask.java:172)
        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.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:179)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:135)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:122)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
        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:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        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:248)
        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:241)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
        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:625)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
        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 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: com/github/shyiko/ktlint/core/Rule
        at com.github.shyiko.ktlint.ruleset.standard.StandardRuleSetProvider.get(StandardRuleSetProvider.kt:8)
        ... 57 more
Caused by: java.lang.ClassNotFoundException: com.github.shyiko.ktlint.core.Rule
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 58 more

I opened this issue with ktlint to which I got the response:

java.lang.ClassNotFoundException: com.github.shyiko.ktlint.core.Rule indicates that com.github.shyiko.ktlint:ktlint-core (transitive dependency of com.github.shyiko:ktlint) isn't available on the classpath. Looks like artifact resolution / class loading / misconfiguration issue (most definitely not a ktlint problem).

I'm not sure why this happens only immediately after running a clean.

Version Info

------------------------------------------------------------
Gradle 4.2
------------------------------------------------------------

Build time:   2017-09-20 14:48:23 UTC
Revision:     5ba503cc17748671c83ce35d7da1cffd6e24dfbd

Groovy:       2.4.11
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_92 (Oracle Corporation 25.92-b14)
OS:           Mac OS X 10.12.6 x86_64

Spotless Version: 3.5.1
Ktlint Version: 0.9.2

@JLLeitschuh JLLeitschuh changed the title Error from spotless after running a clean before linting Error from spotless after running a clean before ktlint linting Oct 25, 2017
@nedtwigg nedtwigg added the bug label Oct 25, 2017
@nedtwigg
Copy link
Member

I think I found it. Resolving dependencies and creating the classloaders that run the formatters is pretty slow, so we cache them in SpotlessCache.

We added SpotlessCache.clear() as a doLast() on the clean task. My faint recollection is that it was helpful for debugging new Spotless formatters, especially for switching from mavenLocal during debugging to mavenCentral for shipping.

The worst bug here is that it should be impossible for SpotlessCache to have this race condition silently. At the very least, it should be loud if there's a problem.

The easy-to-fix bug here is that all of the SpotlessTasks ought to have a mustRunAfter(clean).

The workaround for now is don't call clean and spotless in the same gradle run. If nobody else gets to it, I'll try to fix this weekend.

@jbduncan
Copy link
Member

jbduncan commented Oct 31, 2017

The worst bug here is that it should be impossible for SpotlessCache to have this race condition silently. At the very least, it should be loud if there's a problem.

Hmm, I do not yet see what race condition you're referring to. Would you kindly clarify things for me? :)

@nedtwigg
Copy link
Member

  • Spotless starts using google-java-format for some processing task
  • clean is called in the middle, which closes the classloader that Spotless was using
  • Spotless now fails

I didn't see a way to make this failure louder than it already is.

@jbduncan
Copy link
Member

Okay, I understand now. Thanks for the explanation. :)

I don't see a way of making this sort of failure louder either, so I'm happy with your diagnosis.

nedtwigg added a commit that referenced this issue Oct 31, 2017
clean now runs after all SpotlessTask.  Fixes #159.
@nedtwigg nedtwigg reopened this Oct 31, 2017
@nedtwigg
Copy link
Member

This is now available in 3.7.0-SNAPSHOT. Can you confirm that your issue is fixed @JLLeitschuh?

@JLLeitschuh
Copy link
Member Author

I'm in CA for Kotlin Conf and visiting friends (vacation). I'll let you know when I get back on Thursday.

@JLLeitschuh
Copy link
Member Author

JLLeitschuh commented Nov 15, 2017

Is there a sane way for me to checkout this change and try it given it's not available through the portal?

More specifically, what repo should I use? I'd love to just the build in with the composite build feature but that may not work given how old the version of gradle spotless is built with.

@nedtwigg
Copy link
Member

Use https://oss.sonatype.org/content/repositories/snapshots/ as the repo, and 3.7.0-SNAPSHOT as the version.

https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/spotless-plugin-gradle/

@nedtwigg
Copy link
Member

nedtwigg commented Dec 2, 2017

The fix has been published in 3.7.0. Can you confirm that it is fixed, and if it is, close this issue @JLLeitschuh ?

@JLLeitschuh
Copy link
Member Author

Will do!

@JLLeitschuh
Copy link
Member Author

This seems to have completely resolved the issue! Nice! Thanks!

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

No branches or pull requests

3 participants