Skip to content

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

Closed

Description

@JLLeitschuh

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

Activity

  1. changed the title [-]Error from spotless after running a clean before linting[/-] [+]Error from spotless after running a clean before ktlint linting[/+] on Oct 25, 2017
  2. nedtwigg commented on Oct 25, 2017

    @nedtwigg
    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.

  3. added 2 commits that reference this issue on Oct 31, 2017
    b3caf72
    9707b1c
  4. jbduncan commented on Oct 31, 2017

    @jbduncan
    Member

    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? :)

  5. nedtwigg commented on Oct 31, 2017

    @nedtwigg
    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.

  6. jbduncan commented on Oct 31, 2017

    @jbduncan
    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.

  7. added a commit that references this issue on Oct 31, 2017
    e3556dd
  8. nedtwigg commented on Oct 31, 2017

    @nedtwigg
    Member

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

  9. JLLeitschuh commented on Nov 6, 2017

    @JLLeitschuh
    MemberAuthor

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

  10. JLLeitschuh commented on Nov 15, 2017

    @JLLeitschuh
    MemberAuthor

    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.

  11. nedtwigg commented on Nov 15, 2017

    @nedtwigg
    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/

  12. nedtwigg commented on Dec 2, 2017

    @nedtwigg
    Member

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

  13. JLLeitschuh commented on Dec 4, 2017

    @JLLeitschuh
    MemberAuthor

    Will do!

  14. JLLeitschuh commented on Dec 4, 2017

    @JLLeitschuh
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions