I have a problem with the following odd behaviour of the IntelliJ IDEA development environment (version 14) with scala:
After I reset the (global) scala SDK from a 2.11 version to version 2.10.4 the source code editor shows many compilation errors: list, map, print, (1 to n) etc. are all red.
The SDK is added to global libraries and the jars are all found.
However the code compiles and runs correctly (I rebuilt the project to force recompilation). Has anyone ever experienced something like this?
How can this be fixed?
I am using tha java sdk 1.7.0_55.
In file menu, Invalidate Caches / Restart
also set Incremental Type to SBT in Settings -> Build, Execution, Deployment-> Compiler -> Scala Compiler
There are high chances that you didn't load your project properly, and that's why the errors are appearing. I have written a complete blog post about how you can fix it. And following are the two methods from the write up which can correct your issue.
These two steps should be able to help you, for rest of them please check the link.
1. Importing Project as an SBT Project:
First of all, close your project and import it again after selecting the directory and choose SBT as an External Module. Select Import Project, then go to the project directory, select your project, choose Import Project from external model, opt for SBT and click Next and then Finish. IntelliJ IDEA will ask you to overwrite the .idea file, say Yes to it. After IDEA is done indexing and loading your project, all the issues will be sorted out. The editor will work fine, and you will have your missing features restored.
2. Fixing missing project files with SBT-IDEA:
Sometimes IntelliJ IDEA misses out on the most important project files and shows editor errors along with a broken code completion, however, during the code compilation, everything works as per your expectation. This solution works with a plugin called as SBT-IDEA. Now to enable this plugin, open your terminal and follow the instruction:
a. Create a file plugins.sbt in the directory ~/.sbt/0.13/plugins
b. Now, write the following content to it:
resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.7.0-SNAPSHOT")
Note: Please check for the latest version at the plugin’s GitHub page.
Save and quit, and execute sudo sbt gen-idea in your project root directory.
I hope it helps!
Thank you.
In my case I changed build.sbt file (added empty line and saved file). Then I Idea re-checked dependencies and indexed. Then everything worked fine.
To remove all the false errors sometimes you need to disable type-aware highlighting
by pressing Ctrl + alt + shift + e for example:
https://blog.jetbrains.com/scala/2011/03/02/type-aware-highlighting/
The errors seem to be caused because Scala plugin re-implements compiler logic and that is imperfect.
More information here in the comments:
https://www.reddit.com/r/scala/comments/5pcwfv/question_what_causes_intellij_idea_highlighter/
This occurs when IntelliJ tries to build your code by itself and fails miserably.
If you know your build is successful, all you need to do is edit the Run Configuration and remove the Build part inside the Before Launch part.
This solution solved it for me!
Try invalidating your caches and restarting IDEA.
(File > Invalidate Cache)
Wait for IDEA to re-index your project (Status indicator on lower right status bar). The caches will sometimes become corrupted. This is most likely to occur upon reorganizing a project as you mentioned you did.
Related
IntelliJ crashed for me, and in doing so it lost all of my files. They where still in the project folder itself and in git, but within the project window they where gone. I re-installed IntelliJ, and now there are several style issues.
The first is that used code is being marked as unused, and the second is that the colors for the styles are not being displayed either. This is with the new Scala plugin as well (3.0.3). I have already tried clearing the cache to no avail.
EDIT: Throw into the mix IntelliJ isn't compiling either so Im unable to even go to definition anywhere now.
When I see this sort of problem in Intellij, I first try "Refresh all SBT projects." Before I discovered where that was, I used to add a blank to build.sbt and then opt to Refresh at the prompt that popped up. Something similar exists for Maven projects, but I don't have experience with those. In more extreme situations, deleting the project and reimporting use "Import Project" has worked.
I'm completely new to development using Play or IntelliJ for that matter. I've created a simple HelloWorld application using Activator, and this is an sbt project.
I've been trying to import this to IntelliJ and this is the screen I'm stuck at:
https://www.dropbox.com/s/we1a4a3184sojvb/Screenshot%202014-07-24%2016.57.11.png
In almost all tutorials I've been through online, I've seen people using an sbt option on the import screen. I've installed the SBT plugin as well, but that hasn't helped. I've restarted IntelliJ several times to no avail.
Where am I going wrong?
I'm running 13.1.4 with the SBT plugin installed.
I had this error when importing a new module from existing sources.
On the right-hand side of your IntelliJ window, you will see a list of vertical tabs, open the SBT tab.
Select the module that's causing trouble, right click on it, select "Detach external project"
Try to import the module again.
Move to /your-project-folder
Run ./activator
Type idea . It will generate IDEA project.
Open (not import) File->Open.. project in IDEA.
I had a similar problem which came from a different place than the other solutions here so adding it in case it occurs for others.
In my case the problem was caused by accidentally opening the IdeaProjects directory. When you do this, it creates the .Idea folder in that directory, and populates it as a project. This apparently also confuses the set import.
The solution is to remove the .Idea folder and open (not import) the directory again.
I encountered the same error when I was trying to import a new scala project A to an existing IntelliJ project B as a module. I solved the problem by following step below:
Go to your folder of project B. Open file .idea/sbt.xml.
Deleting the entry which includes the path of project A.
After a series of struggles, I must say something weird solved this problem – moving to IntelliJ IDEA Ultimate. That has built in Play application support and can run/debug/test the application out of the box, which is very handy.
All I can say after this experience was that JetBrains wants you to upgrade to Ultimate if you want things to work right out of the box.
I'm sure there are ways to get this working with CE also, but I wasn't successful with that.
Solved for
IntelliJ IDEA 2022.2.1 (Ultimate Edition)
scala plugin: 2022.2.12
sbt version: 1.7.1
doing these steps:
Unlink sbt Project(sbt toolbar), then link it again.
Delete modules (ctrl + alt + shift + s).
Remove .bsp/, and .idea/ config files.
Invalidate caches..(ctrl + f).
Restart IDEA.
The number of steps to make it work may vary.
Uninstall everything
Reinstall IntelliJ
Install the JetBrains official Scala plugin
Import the project
Make sure that the project has a build.sbt file in the right place, so that IntelliJ can find it as an SBT project.
This is about IntelliJ IDEA version 13.1.4.
This issue is solved in the latest updates of the SBT and Scala plugins.
Make sure that your java path is correct (IntelliJ can use other path than system defined)
Preferences -> Build, Execution, Deployment -> sbt -> JVM - choose a
correct JRE
I've been having a problem with eclipse that's been stressing me a lot. Whenever I start a new Java porject, everything goes smoothly and perfect, until I "clean" the project (Project -> Clean...) and everything goes to ##~%&...
I keep getting:
XYZ cannot be resolved to a type
Multi-catch parameters are not allowed for source level below 1.7
<> operator is not allowed for source level below 1.7
That's very nice, only that I am importing all required classes and I do have 1.7 since the begginig. It's the only version I've installed. I've already tried this and other similar responses for the last few days with no avail.
A solution was to create a new project, copy and paste all packages/clases, which worked for a while, but I added UMLet to the project and again... Removing UMLet plugin did nothing for me.
BTW, even with the "errors", my project runs without any problem, therefore I know they're not real. I could keep working, but then, I can't see when a real error arises...
Does anyone got a final solution to get rid of this false errors?
EDIT:
I forgot to mention that I'm working with Kepler.
EDIT 2:
Here are screen captures with the requested information.
You can solve this by setting up correct JRE environment in Eclipse as below.
Go to Project => Properties => Java Build Path
Click on Libraries
Select JRE System Library
Click on Edit button at right hand side
Set Execution Environment to Jave SE-1.7(jre7)
Clean project or refresh project.
A solution was to create a new project, copy and paste all packages/clases, which worked for a while, but I added UMLet to the project and again...
One possibility is that the UMLet plugin is the cause of your problems. Try a clean Eclipse install without UMLet. (The fact that uninstalling the UMLet plugin didn't fix the problem is in no way conclusive.)
Note that UMLet will run as a stand-alone tool.
BTW, even with the "errors", my project runs without any problem, therefore I know they're not real.
The likely explanation for that is that the compilation errors come from the incremental Java compiler that is built into Eclipse. A different compiler (i.e. the one from your installed / configured JDK) is used to generate the ".class" files.
Multi-catch parameters are not allowed for source level below 1.7
not a solution, to this issue, but if you want to have two exceptions you can code it like this:
try {
// code here
} catch {
// code here
} catch {
// code here
}
it worked for me, instead of having catch (exception1 | exception2 e)
I'm running IntelliJ IDEA 12.1.3 on Windows 8 with the Scala plugin 0.7.264. Scala is installed in C:\Apps\Scala\scala-2.10.1, and that directory is in my PATH. The Scala docs are in C:\Apps\Scala\scala-2.10.1\doc\scala-devel-docs\api. These are manual installs from the .zip files.
Everything seems to work fine except for two things:
First, if the "Run compile server (in external build mode)" settings is enabled (as it is by default), I get this error:
Turning off that setting fixes that for now, but there is another problem. I can run my code in the debugger and see values change in the debugger panel as I single step through the code, but it doesn't synchronize the source file view as I step through.
Normally I'd expect to see the current line being executed turn green, and the green highlight would follow along as I hit F10 or F11 to step through, but it doesn't. I can set breakpoints on source lines and let it run, and it stops at each breakpoint as expected. It just doesn't highlight the source line in green when it gets there.
Similarly, if a source file is not open (either my source code or a library file), and I step into that code, it appears to single-step correctly but does not open the source file at all.
Everything else works fine, like the autocompletes and Shift+F1 to view the Scala docs for the name the cursor is on.
The really odd thing is I had full debugging working briefly. At first I'd installed Scala from the .msi file, so it installed Scala into C:\Program Files (x86)\scala. When I set up IntelliJ to use that Scala installation I did get the green highlight on source lines as I stepped through the code.
The only problem with that setup was that IntelliJ complained about the missing doc\scala-devel-docs\api directory when I'd setup a Scala project, because the .msi installation uses a different subdirectory for the API docs. It was easy enough to fix that up manually in the Global Liraries settings, but I figured I'd try the .zip installation so I could use a directory layout more like what IntelliJ was expecting.
I should have left well enough alone! I even tried going back to that arrangement and still didn't get source line synchronization working again.
At one point I also tried letting IntelliJ do the Scala installation, but that also gave the same results: everything working except source line synchronization in the debugger.
There must be some obvious thing I got wrong, but I'm not sure what it could be. Does anyone have any ideas?
Here's a screenshot from a debug session:
The program is stopped on line 3, as indicated by the values assigned to x and y but not yet to z, and the <init>():3, Main$$anon$1 in the Frames panel. So line 3 should be highlighted in green but isn't.
Here are the relevant settings dialogs:
The above is with "Run compile server" on; as mentioned I ended up turning that setting off. The field values are the defaults, including the -server -Xss1m -XX:MaxPermSize=256m JVM parameters.
I am using the same version of IDEA and the Scala plugin (however on OS X and JDK 6), and I do not have this problem. Does this occur with any of your projects or only a specific one?
Assuming that the OS shouldn't be responsible, the difference is that I use sbt to build my projects. So if you are willing to set up a build.sbt and installing the SBT plugin for IDEA, this might be worth a try.
Although the fancy new compile server should in theory be as fast and smooth as sbt, I find it very pleasant to work with the sbt plugin. You can install it from Settings -> IDE Settings -> Plugins. Next step I also highly recommend is to use the sbt-idea plugin, which is like the complementary to the IDEA SBT plugin—this will allow you to generate the full IDEA project files from sbt (you can have as little as a single scalaVersion entry in build.sbt if you don't need to manage dependencies, so you don't need to learn much of sbt in the first place).
The final step then is to go into your Run/Debug configuration, and change in the "Before launch" section from "Make" to "SBT".
Finally you might get better support for your problem through the JetBrains online forum.
I have Playframework 2 project with Scala (very small one). It uses Scala Anorm library.
I have the code like this:
package models
..
import anorm.SqlParser._
...
val rowParser = scalar[Long]
So, I would like to see source of scalar method. Trying to attache the sources I have in my plaframework source folder, but IDEA just swallows my request and does nothing back.
I use last version of IDEA and Scala plugin. Is it bug, probably?
First download source code :
1.) Click on this link : http://www.scala-lang.org/download/all.html
2.) Choose any scala version.
3.) Now in the last section 'Other Resources' you can see 'Sources' link. Click on it to download. In my case (https://codeload.github.com/scala/scala/tar.gz/v2.11.7)
Now point to this Source Code from IntelliJ.
1.) Open Project Structure in IntelliJ. Shorcut (Cmd + DownArrow)
2.) Select Global Libraries from the left section.
3.) Then on right side, Under 'Scala Library' section. Click '+' and point to source directory. See the screenshot.
Aha.. fixed.
So: I used to use 'attach source' in the top of the window editor - it does not work (I guess it is a bug - maybe related to the scala plugin, because usually it works).
But if try to attache sources to particular library - in "Project Structure -> Library -> +Attach File or Directories -> Sources" then it works.
Thanks.
To fix it we need to do some changes into IntelliJ IDEA platform. Most probably it will be fixed in IntelliJ IDEA 13.1.
I have the same problem. I installed "Scala Imports Organizer", and problem was solved.
for "automatically attaching source jars" when using Bloop and BSP you can add one line:
bloopExportJarClassifiers in Global := Some(Set("sources"))
to your build.sbt, also sbt updateClassifiers, also Reload all BSP Projects to refresh, also Invalidate Caches/Restart to trigger indexing (if not done automatically)
reference