Okay. So i ahve this problem concerning itelliJ revolving around SBT and Scala.
The problem is that intelliJ cannot correctly import the project, and i am left with an intelliJ that recognizes only false syntax errors and which cant compile from the "run" bottom integrated within the IDEA.
When I start IntelliJ/Open the project, the SBT goes to work and tries to index the project, after which it fails, returning me multiple errors.
Extracting structure failed: Structure file /tmp/sbt-structure.xml is empty
Picture of additional erros
The thing is, that the code works, using the terminal it can both compile and run!
I feel like i have traversed the internet and done multiple things including:
Reload SBT.
Try to Import the project with SBT.
Reinstall plugins.
Restart and invalidate cahces.
Thanks in advance!
Related
When I open a maven module with scala code (link) which compiles and runs fine, I get bad error highlights:
Code-complete seems broken as well. How to fix this? (I don't want to switch to SBT since I only want this one module in the project to use scala, and I've tried the "Invalidate Caches / Restart" fix suggested here in vain.)
It is a known problem in IntelliJ with Scala because of the complex type system of scala.
I mostly use sbt. If I encounter such problem, first I compile it with sbt in the command line, most time wrong error highlights disappear.
If this does not help, clear IntelliJ cash and restart it (File -> Invalidated Caches / Restart).
I am doing the Scala introductory course from Coursera.
Within Intellij, I am trying to debug but breakpoints are ignored.
Unlike in this question: Can't debug a Scala application in IntelliJ + sbt-idea-plugin, I am not getting any error.
Do I need to install something or set some Intellij configurations?
Someone recently walked me through debugging in InteliJ using scala/scalatest. I am running InteliJ Idea 2017.2 with the latest scala language plugin installed, no SBT plugin installed (as far as I can tell this is just part of the scala plugin now). Hopefully this helps some other people out:
Set breakpoints by clicking next to the line number you want to test.
Assuming you are using ScalaTest to set up some conditions and run your program, you can right-click on one of your test classes, and then select Debug '[classname]' from the dropdown. This should pop open the debug pane on the bottom.
When you use InteliJ to run the debugging directly (not attaching through sbt etc) I was actually able to get this to work. I have not had success with any of the answers to related questions that discuss attaching to a running sbt process (with scalatest at least).
There are a lot of useful things that intelij debug gives you with scalatest at this point. Say there is one test that is failing and you want to dig into why. On the debug window, click the console tab, and you will see a list of your tests ordered by suite w/ red marks next to the ones that failed. You can right-click on a single test and select debug from the dropdown to only debug that one test. It's pretty useful.
Hopefully that helps some other people! I also hit a few gotchas I should outline:
Sometimes I need to re-load the sbt project (click the circular arrow thing under the sbt project tab on the left). It takes a while but it cleans up some random errors about classes not being found, and even unrelated sounding things like One or more requested classes are not Suites.
I sometimes get errors about shaded classes not found, especially when using docker through sbt (for example to spin up a db node in my tests). To get around that I first deleted the cached compiled jar (rm -r $HOME/.ivy2/cache/com.spotify/ for example to get rid of the cached compiled code that was causing problems) then I reloaded the project as in step-1.
If all else fails, make sure that the project is properly imported. You might need to delete the .idea folder in your folder and re-import the sbt project. This trashes your settings and all, but it's worked for me as a last resort in the past.
If I run my application (Play 2.3.2) while Eclipse is running I always have strange compilation errors, no class def found errors, class not found errors, etc...
If I exit Eclipse and run my application, everything is working fine. But sometimes it's also working fine while Eclipse is running.
Am I the only one to experience that ? What is the cause ?
I suspect something in Eclipse changes my source files but I can't find what.
Maybe Lombok ?
Thanks.
I have similar problems. Typesafe responded with a solution which I am currently trying out.
https://groups.google.com/forum/#!topic/play-framework/4RnbqEk-muM
Brief summary of the answer by #jroper :
Eclipse doesn't know
how to keep its dirty hands off the same build directory that Play is
using to compile your app - if you have both Play, and the IDE, trying
to compile the same code at the same time, what do you think will
happen? You will see random errors. You should configure Eclipse not
to automatically build your app, or configure it to have different
output directories.
The Play Framework compiles everything to the directory target/scala-2.11/classes. When changing some of these classes, especially any views, causes Activator to auto compile the classes creating new class files. Hitting refresh on the project in Eclipse will update the project and class files in the classes directory causing a rebuild. This should make your compilation errors go away. If you still have issues, take a look at your .classpath file and the Eclipse build path settings.
I'm working with project in intellij IDEA IDE based in maven. I can perform all maven goals but IntelliJ is showing a lot of errors in the source code like bellow:
Everything worked fine a few hours ago. I don't understand why the IDE continue
showing errors. When I rebuild or compile the entire project (CTRL + F9) or a single
scala class I always receive a success message like that:
I already had configured scala plugin before, so I don't know what is happen.
thanks for your help
Sometimes the IntelliJ cache gets corrupted. You can fix this by the following:
File > "Invalidate Caches / Restart"
After choosing "Invalidate and Restart" when prompted, IntelliJ will restart and rebuild its cache.
If IDEA has lost track of obviously correct types such as Database or DateTime it probably means the configuration of the project is wrong or corrupted. Most commonly it does not have the required 3rd part dependencies such as Joda Time.
If you're not already doing so, define your project solely in SBT and use the sbt-idea plug-in to produce your IDEA project definition. Then whenever you change the project dependencies, re-run gen-idea to regenerate your IDEA project files. No muss, no fuss.
There are many bugs raised in jetbrains's bug tracker for this. I suggest you raise some bugs or vote for existing ones.
It loos like the problem you have is with the type aware highlighting which is worse than useless.
thanks for your responses.
I solved this problem importing the project again.
This is a bit weird, I've got IntelliJ IDEA 10, a fairly recent Scala plugin on it and sbt 0.7.7. I've been using the same setup on the same project for a while and syntax highlighting worked perfect.
After a few clean/compiles from sbt (I'm not really sure about the action), everything from Scala._ is red. For instance, List() is red but when I import scala.collection._ it gets fixed. The project compiles without any problems in both IDEA and SBT. What may be the problem?
(new/other projects are OK on the same setup so I guess I've messed up something but I have no clue where to look for it)
Thanks
I've never found a single solution to this, so i generally try all the things.
sbt gen-idea (to recreate IDEA project meta-data)
File > Invalidate Caches ... > Invalidate and Restart
After invalidating caches, upon restart IDEA will re-index all of your class files.
Usually I'll try
sbt> clean
sbt> gen-idea
Then if it didn't work go for invalidating caches. If that still doesn't work (and it almost always does) try deleting the following directories and then perform #1/#2 from above again:
target
project/target
.idea
.idea_modules
at project Settings, add the jars to its dependencies of IDE, then you will get the red away.
SBT is one thing, IDEA is another, they use their own way to compile scala. some sbt plugin for idea is also something that just hook sbt command line to idea's panel.
This sometimes happens to me when the SBT and IDEA projects get out of sync. Simply run the SBT Idea processor again - this regenerates your Idea project files.