how to debug scala sbt project in vs code - scala

I am trying to debug sbt project in vs code. I have downloaded vs code extension name scala metals. How to explicitly add build.sbt folder path in scala metal.

How to explicitly add build.sbt folder path in scala metal
Open the root of your Scala project via VSCode, and Metals should detect your build.sbt and ask you if you want to load it. Otherwise you can do it explicitly from the Command Palette (Ctrl+Shift+P) and write "Metals Import Build"
how to debug scala sbt project in vs code
Not sure how to do it via metals. But the way I do it, is to open sbt myself from the terminal, via sbt -jvm-debug 5005. Then I attach VSCode remote debugger. You'll have to install "Debugger for Java" VSCode plugin too.

Here is the official documents: https://scalameta.org/metals/docs/editors/vscode.html,
See the "Running and debugging your code" sections.
But I found it's hard for me to debug the web project based on play framework.
So I use inntelij instead.
Start the project in sbt with: sbt --jvm-debug 5006
You can run it in the terminal:
After entered sbt, type "run" to start the proejct.
Add a new debug configuration, set port to: 5006
And then click "run->debug...", you can add the breakpoint.

Related

how can I change the coursier cache directory of the bundled sbt in IntelliJ

I've migrated my local coursier cache to another part of my system and changed the COURSIER_CACHE system property, as described in the coursier docs
My local installation of SBT works fine with this, via shell as well as via IntelliJ's sbt shell. However, when building my app using IntelliJ's build-in SBT using CTRL+F9, I get the following error:
scalac: Scala compiler JARs not found (module 'solipsism'): C:\Users\<user>\AppData\Local\Coursier\cache\v1\https\repo1.maven.org\maven2\org\scala-lang\scala-library\2.13.5\scala-library-2.13.5.jar, <etc>
with C:\Users\<user>\AppData\Local\Coursier\cache being the default coursier cache location.
So far, I tried to add the following VM Parameters to the Settings > Build Execution Deployment > sbt > VM Parameters without success:
-Dcoursier.cache=<repo dir>
-Dsbt.coursier.home=<repo dir>
as described in the SBT docs and in the coursier docs again
Verifying these settings via IntelliJ's SBT shell using csrCacheDirectory shows that they were picked up correctly, but the build error persists.
How can I change the coursier cache directory for the default build?
Using Windows 10, IntelliJ CE 2021.1.1, SBT 1.5.1
Thanks,
Cheers,
Joost Papendorp
Found the cause: IntelliJ had somehow retained the links to the old repository in the project structure. This is apparently not fixed by re-importing the project.
Solution: Delete entire Intellij project (not just the modules). Close IDE. Start new project. Re-import modules.
Classy.
https://get-coursier.io/docs/cache#sbtd mentions two options:
-Dsbt.coursier.home system property, or
COURSIER_CACHE environment variable

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.

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

How to execute SBT plugin's tasks from within IntelliJ IDEA CE?

I use IntelliJ IDEA 13.1 Community Edition with the Scala plugin 0.32.593.
What's the recommended way to execute a SBT plugin's tasks, say dependencyUpdates from sbt-updates?
In version 15 of IntelliJ IDEA, using Scala Plugin version 2.0, you can run SBT tasks by adding a run configuration.
First add a new run configuration by clicking on Run -> Edit Configurations. Then click the + button to add a new configuration and choose SBT Task form the list
Now provide the list of tasks separated by space in Tasks input box:
NOTE IntelliJ IDEA and the Scala and sbt plugins have improved since and you may want to read How to run sbt-assembly tasks from within IntelliJ IDEA? instead.
I worked it around with the Embedded Terminal plugin that shipped with the version of IDEA.
Alt+F12 (or Tools > Open Terminal) to open a terminal window and then sbt dependencyUpdates inside.
It does require a local installation of SBT.
Unless there has been a recent change (in 13.1), SBT plugin doesn't support running sbt tasks.
See comments here http://blog.jetbrains.com/scala/2013/11/18/built-in-sbt-support-in-intellij-idea-13/
You will have to run these two commands to run SBT in the terminal:
SBT_OPTS="-Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M"
java $SBT_OPTS -jar `<SBT inatall>`/bin/sbt-launch.jar "$#"