JetBrains / intellij-platform-plugin-template

Template repository for creating plugins for IntelliJ Platform
Apache License 2.0
2.97k stars 587 forks source link

Default cache settings seem to cause problems with newly created test classes resulting in a `ClassNotFoundException` #426

Closed ChristianIvicevic closed 4 months ago

ChristianIvicevic commented 6 months ago

What happened?

I noticed that every time I create a new test class and attempt to run it, either via the gutter icon or the Run Tests task that I receive a ClassNotFoundException despite the class file being in the build folder as seen in the attached screenshot. My gut feeling is that something with the preconfigured caching behavior of Gradle might be wrong. The only way I can make Gradle recognize the new files is by restarting IntelliJ itself and triggering a full rebuild of the plugin. Any suggestion how to resolve this would be appreciated.

CleanShot 2023-12-25 at 21 55 43@2x

Relevant log output or stack trace

Calculating task graph as configuration cache cannot be reused because the file system entry 'build/classes/java/main/classpath.index' has been created.
> Task :initializeIntelliJPlugin SKIPPED
> Task :checkKotlinGradlePluginConfigurationErrors
> Task :processTestResources NO-SOURCE
> Task :koverFindJar UP-TO-DATE
> Task :patchPluginXml UP-TO-DATE
> Task :generateLexer FROM-CACHE
> Task :processResources UP-TO-DATE
> Task :verifyPluginConfiguration
> Task :generateParser
WARN: Attempt to load key 'psi.sleep.in.validity.check' for not yet loaded registry
WARN: Attempt to load key 'psi.incremental.reparse.depth.limit' for not yet loaded registry
ClipsParser.bnf parser generated to /Users/christian.ivicevic/Code/Personal/intellij-clips/src/main/gen
> Task :compileKotlin UP-TO-DATE
> Task :compileJava UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :instrumentCode UP-TO-DATE
> Task :jar UP-TO-DATE
> Task :instrumentedJar UP-TO-DATE
> Task :prepareTestingSandbox UP-TO-DATE
> Task :compileTestKotlin
> Task :compileTestJava NO-SOURCE
> Task :testClasses UP-TO-DATE
> Task :instrumentTestCode

java.lang.ClassNotFoundException: com.jetbrains.clips.language.ClipsSampleErrorTest
    at com.intellij.util.lang.UrlClassLoader.findClass(UrlClassLoader.java:246)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:467)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:66)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:40)
    at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:60)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:52)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    at jdk.proxy1/jdk.proxy1.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
    at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
    at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113)
    at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65)
    at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
    at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)

> Task :test FAILED
CompileCommand: exclude com/intellij/openapi/vfs/impl/FilePartNodeRoot.trieDescend bool exclude = true
com.jetbrains.clips.language.ClipsSampleErrorTest > initializationError FAILED
    java.lang.ClassNotFoundException at UrlClassLoader.java:246
1 test completed, 1 failed
> Task :classpathIndexCleanup
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.

Steps to reproduce

Scaffold a new plugin from the template, add a new test file and try to run it which causes the error.

Gradle IntelliJ Plugin version

1.16.1

Gradle version

8.5

Operating System

macOS

Link to build, i.e. failing GitHub Action job

No response

bric3 commented 6 months ago

I have a supposition that the test's classpath.index file might not be up to date, ie even if it's cleared after the test, the file might be older.

If I'm leaning towards this is because while trying to debug, I found the com.intellij.util.lang.PathClassLoader that is used as a system classloader, which is difficult to debug (due to being a system classloader). But in reading the source file I found out that to load a class it first try to pick that class from classpath.index, and if the answer is no then it leads the the NCDFE.

Removing the classpath.index file in the build test resources folder doesn't work as the one from the gradle cache is retrieved. However I can clearly see that after compileTestKotlin --rerun the hash of the classpath.index file is different and there's no CNFE.


Also I think this is an issue with the gradle-intellij-plugin, hopefully fixed with v2.

ChristianIvicevic commented 6 months ago

Your observation also indicates this is like a problem of gradle-intellij-plugin instead. @hsz Do you want me to move this issue over into that repo instead?

bric3 commented 6 months ago

This fix could be related https://github.com/JetBrains/gradle-intellij-plugin/issues/1515

bric3 commented 4 months ago

@hsz I think this one can be closed since 1.17.1