Cannot resolve package from Scratch file
Answered
After updating this morning, my scratch file can no longer resolve packages in the project. I have tried invalidating caches and deleting .idea directory and re-importing pom.xml as suggested in other posts but this doesn't help.
There are no errors displayed in the editor and ctrl-b on the import statement correctly highlights the package in the project view panel.
IntelliJ IDEA 2019.1 (Community Edition)
Build #IC-191.6183.87, built on March 27, 2019
JRE: 1.8.0_202-release-1483-b39 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
Please sign in to leave a comment.
Please share a sample project to reproduce: https://uploads.services.jetbrains.com/ .
I have uploaded jn-2019-03-29-myframework.zip which is a simple project demonstrating my issue. If I create a scratch trying to access the 'Add' function in MyClass, I get an error that the package does not exist.
Works for me:
Make sure you have module classpath specified in the Run configuration as shown on the screenshot. Also try Build | Rebuild Project.
This has resolved the issue for me, thank you. Can I ask why this setting was changed between upgrading from the previous version though? I wouldn't have previously ever changed the classpath setting in the run configuration when I created the scratch and it was running fine until the upgrade to 2019.1.
The answer provided by @Serge Baranov is not working for me. I tried on different machines using the same gradle project.
After downgrading to 2018.3.6 everything is working again.
@Ts, here's what resolved it for me:
I think initially Java Scratch wasn't selected for me and it was on the JUnit section so might be worth checking you have the Scratch selected in the tree view?
Thank you for the steps
Hi,
I upgraded again, this time to version 2020.1. Before that I removed everything related to Intellij in my home and install directory and even in the projects themselves. Unfortunately I still experience the same problem even though following the steps above, which btw. should be improved in any case as this is extremely confusing when no error is displayed in the editor. Why was the default to use the module classpath even changed in version 2019?
I tried to create a sample project. But there is nothing worth uploading. Even with a fresh project with a single class with one public static method, the method can not be called in my a scratch, build failing with 'can not find symbol'.
Please try creating multiple projects with different scratches, maybe also one with gradle like i did one my machine, to reproduce the error or give me a hint how I could help investigating this.
Do you see this error
Caused by: java.lang.ClassNotFoundException: Scratch
Similar to one of our bugs: https://youtrack.jetbrains.com/issue/IDEA-197627
Thanks Konstantin, that post describes the problem exactly: https://youtrack.jetbrains.com/issue/IDEA-197627#focus=streamItem-27-3920740.0-0
So yes, when IDEA-197627 is solved and scratches start working without the need to change any run configurations, this issue here would be fixed for me.
Thanks again for looking into this.
I can confirm this bug is still present in 2020.1.2. Also the ticket IDEA-197627 specifies Gradle, but in reality this bug affects Maven as well.
Any ETA on the fix? Java8 can't use the jconsole so if we cannot use scratches we basically cannot run/test/debug java snippets anymore and we are forced to downgrade.
>but in reality this bug affects Maven as well.
Do you have Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Maven | Runner | Delegate IDE build/run actions to Maven option enabled? If not, could you please provide a sample with the steps to reproduce at https://youtrack.jetbrains.com/issues/IDEA Thank you.
I don't have delegate on (it just hangs if I enable that and try to run a scratch snippet). I've added the steps to reproduce it, which are none, just make a scratch and run it.
Most probably, the issue is caused by environment/settings, as we cannot reproduce that on our side. That is why we asking you to share your environment info and logs folder to https://youtrack.jetbrains.com/issues/IDEA.
Still not resolved. Copying out the absolute path of the scratch file and replacing "Scratch" in the output in the failed run dialog and pasting it into the terminal does however work.
FWIW This is also happening for me in PyCharm as well. The code inspection is broken but I can run the file successfully.
I'm experiencing the same issue with a Kotlin scratch file. with the class path set to use the module class path and after a gradle build, It seems the scratch file can't find the classpath. There is no run configuration for this file. Any ideas?
Carl Furst What is the exact error you get? May you show the screenshot?
I seem to be having the same problem with Webstorm.
@... https://youtrack.jetbrains.com/issue/WEB-53972 is fixed in 2021.3.1 update
Thanks Elena Pogorelova