scalac: Token not found: /Users/mpa/Library/Caches/JetBrains/IntelliJIdea2021.3/compile-server/tokens/54149 - scala

What means this exception and how can I fix it?
scalac: Token not found: /Users/mpa/Library/Caches/JetBrains/IntelliJIdea2021.3/compile-server/tokens/54149
I have a Scala 3 project in IntelliJ 2021.3:
It seamed to appear randomly when building the project with IntelliJ.
I tried:
sbt clean / sbt compile and sbt reload.
close IntelliJ / delete .idea folder and open Project newly.
Using sbt works just fine. So adjusting the config like this works, but I want to use the build from IntelliJ:

I faced the same issue with scala 2.13. File -> Invalidate Caches... option in Intellij fxed the issue for me

Related

sbt Project name must be valid Scala identifier error while creating new project

I wanted to create a new project in scala in intellij. I have chosen Lightbend Project Starter and then Akka Quickstart Scala. On finish I got this error:
sbt Project name must be valid Scala identifier
The name of my project is "akka-demo" but "akkademo" and default "untitled" don't work either. Empty catalog is created. Same with other templates. How can I overcome this?
Env:
Intellij idea ultimate 18.3.4
sbt 1.2.6
As mentioned, akkademo should indeed work.
It sounds like an IntelliJ problem.
If a project directory was created, you can try to remove the .idea directory and reimport the project.
Furthermore, you can download the Akka Quickstart Scala project from Lightbend's website, and start the sbt shell in this directory.
Try to run and compile to make sure your environment is set up correctly.
If everything works with the sbt shell but not in IntelliJ, then open:
IntelliJ -> Preferences -> Build, Execution, Deployment -> Build Tools -> sbt and check the Use sbt shell for imports and for builds.
Then go to the sbt tab in IntelliJ and refresh.

Intellij: Error while importing SBT project

I used Intellij for 4 months without any problems. Yesterday I installed it on another PC but I can't create a SBT Scala project.
Here the steps:
I create the project:
When started it says me that "SBT project need to be imported" so I click on "Enable Auto-Import" but then I get this error:
If I try to add Scala SDK from modules settings I get this error:
I downloaded Scala and SBT externally, I also tried all the suggested solutions from other similar threads but I can't resolve it.
How can I do?
Thank you in advance!
Add sbt.version to project/build.properties. You can check SBT version using sbt sbtVersion.

Play Project not compiling correctly in Intellij - routes_routing.scala

I have a simple Play project with one controller (with a route) and a unittest.
When I type "sbt compile test" into terminal it runs fine and the test passes.
I cannot get the solution to compile correctly in IntelliJ however.
Controller: controllers.nisp.LandingPageController
Compile error:
.../nisp-frontend/target/scala-2.11/src_managed/main/app/routes_routing.scala
Error:(37, 18) object LandingPageController is not a member of package app.controllers.nisp
controllers.nisp.LandingPageController.showLandingPage(),
^
Directory structure:
I have solved this issue using the following method:
Upgrade to Intellij 14
Upgrade to the latest scala plugin.
Remove the whole project directory and re-cloned the source.
Use File -> Import Project -> SBT -> Auto-Import.

Intellij unable to resolve references to a specific jar file

In a given project that is driven by sbt there is some kind of corruption in the project libraries specifically for a MavenLocal repository used for kafka-spark-9.7.2.jar in which:
references to the classes provided by that jar are marked as "symbol not found" by the editor parser
however the editor (strangely) does offer to import the classes
but after accepting the import, the symbols are still marked in red as unresolved.
The following attempts to "clean things up" have already been performed:
Build | Make Project
Build | Rebuild Project
In addition I have verified that the project does build from
sbt package
on the command line
UPDATE After re-running sbt gen-idea the librraries are still not found by the Parser. yet the libraries exist -even IJ knows about them as shown in the following screenshot. Why is it that IJ can find the library
C:\Users\S80035683\.ivy2\cache\org.apache.kafka\kafka\jars\kafka-0.7.2-spark.jar!\kafka\api\FetchRequest.class
However IJ is unable to resolve any classes from that library in the Parser?
You have to build the project for Intellij, try to do this in your project root:
sbt idea with-sources=yes
This should build the project structure from scratch and add the right dependencies, usually I refresh the project after adding a dependency or a jar.
Edit:
To use the command you need this plugin, otherwise you can use gen-idea but I used it only a few times and I'm not sure how it will work out.
Edit2:
There was some confusion, first, for the IDEA SBT console you don't need to prepend the sbt command since you already are inside sbt:
If you have the sbt plugin for idea you can use gen-idea with-source=yes (without prepending sbt)
From the terminal, either you go to your project root and type sbt to enter the sbt console and use gen-idea or idea with-sources=yes (without prepending sbt)
or directly sbt gen-idea or if you have the plugin sbt idea with-sources=yes (prepending sbt)
To reach the sbt console inside idea you need to install the sbt plugin on preferences -> plugin and search for sbt and then View -> Tool Windows -> SBT Console:
To start the console click on the play button, to kill the console on the skull.
I had the same problem. I fixed it by directly writing the CLASSES and SOURCES of the problematic library. This can be found in .idea/libraries/SBT__<problematic library>_jar.xml

Editing Build.scala in Intellij

I want to migrate our build from maven to SBT, so now I work separatedly on Build.scala file. However I don't benefit from any syntax highlighting (that is quite obvious, I don't have SBT in my classpath). What is the correct way to get SBT to my classpath, adding sbt-launch.jar does not seem to help.
IntelliJ 13 has built-in SBT support; if you're running a lower version, then you can have a look at their sbt plugin.
There's also an sbt plugin on github for generating idea project files. I've had success with running the gen-idea task it provides.
Run sbt gen-idea. It will create a "YOUR_PROJECT_NAME - build" project within your main project (for whatever your YOUR_PROJECT_NAME happens to be). Under the project folder of the build project, I was able to write a Build.scala with the following code:
import sbt._
object Build extends Build {
}
The SBT Build trait is recognized just fine. I'm running IntelliJ 13 build #IU-133-696, Scala plugin 0.30.378.
Eventually what I did is finished to write my build.sbt stub, and opened a project with it. Now everything seem to work.