4

I am brand new to Scala and I find that Scala IDE is very slow on my machine for basic things like searching the codebase and editing code. I am used to Visual Studio Code and was very happy to find this metals extension.

I was able to "import build" and fix issues like bumping up scala version in my projects but I am not sure how to reproduce this step to set up a run configuration and actually launch our app in Scala IDE.

enter image description here enter image description here

We have a parent folder which has a bunch of projects and a 'consoleapp' project which is the main entry point of our app - it imports the logic/routes of all other projects.

|____parent
| |____consoleapp
| |____project1
| |____project2 

I tried sbt run and sbt runMain consoleapp from within the consoleapp folder and also the parent folder but they didn't work.

I am not sure what other information from our setup is relevant - happy to provide more info as needed.

Updated to add more details below:

consoleapp/build.sbt

name := "consoleapp"

version := "1.0"

scalaVersion := "2.12.10"

packMain := Map("consoleapp" -> "consoleapp")

libraryDependencies ++=  Seq (...)

Output of commands I ran - sbt run and sbt runMain

Running from ~/scala/parent

> sbt run                                                                                                                                                                 masterstate [0a8dab85] modified
[info] Loading settings for project global-plugins from metals.sbt,build.sbt ...
[info] Loading global plugins from /Users/pradhyo/.sbt/1.0/plugins
[info] Loading project definition from /Users/pradhyo/scala/parent/project
[info] Loading settings for project consoleapp from build.sbt ...
... 
Loading settings for all other projects in parent folder
...
[info] Loading settings for project parent from build.sbt ...
[info] Resolving key references (22435 settings) ...
[info] Set current project to parent (in build file:/Users/pradhyo/scala/parent/)
[error] java.lang.RuntimeException: No main class detected.
[error]     at scala.sys.package$.error(package.scala:30)
[error] stack trace is suppressed; run last Compile / bgRun for the full output
[error] (Compile / bgRun) No main class detected.
[error] Total time: 1 s, completed 18-Dec-2019 1:41:25 PM

Running from ~/scala/parent

> sbt "runMain consoleapp.consoleapp"                                                                                                                                     masterstate [0a8dab85] modified
[info] Loading settings for project global-plugins from metals.sbt,build.sbt ...
[info] Loading global plugins from /Users/pradhyo/.sbt/1.0/plugins
[info] Loading project definition from /Users/pradhyo/scala/parent/project
[info] Loading settings for project consoleapp from build.sbt ...
... 
Loading settings for all other projects in parent folder
...
[info] Loading settings for project parent from build.sbt ...
[info] Resolving key references (22435 settings) ...
[info] Set current project to parent (in build file:/Users/pradhyo/scala/parent/)
[info] running consoleapp.consoleapp 
[error] (run-main-0) java.lang.ClassNotFoundException: consoleapp.consoleapp
[error] java.lang.ClassNotFoundException: consoleapp.consoleapp
[error]     at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
[error] stack trace is suppressed; run last Compile / bgRunMain for the full output
[error] Nonzero exit code: 1
[error] (Compile / runMain) Nonzero exit code: 1
[error] Total time: 0 s, completed 18-Dec-2019 1:46:21 PM

Running from ~/scala/parent/consoleapp

> sbt run                                                                                                                                                                 masterstate [0a8dab85] modified
[info] Loading settings for project global-plugins from metals.sbt,build.sbt ...
[info] Loading global plugins from /Users/pradhyo/.sbt/1.0/plugins
[info] Loading project definition from /Users/pradhyo/scala/parent/consoleapp/project
[info] Loading settings for project consoleapp from build.sbt ...
[info] Set current project to consoleapp (in build file:/Users/pradhyo/scala/parent/consoleapp/)
[error] java.lang.RuntimeException: No main class detected.
[error]     at scala.sys.package$.error(package.scala:30)
[error] stack trace is suppressed; run last Compile / bgRun for the full output
[error] (Compile / bgRun) No main class detected.
[error] Total time: 0 s, completed 18-Dec-2019 1:49:26 PM

Running from ~/scala/parent/consoleapp

> sbt "runMain consoleapp"                                                                                                                                                masterstate [0a8dab85] modified
[info] Loading settings for project global-plugins from metals.sbt,build.sbt ...
[info] Loading global plugins from /Users/pradhyo/.sbt/1.0/plugins
[info] Loading project definition from /Users/pradhyo/scala/parent/consoleapp/project
[info] Loading settings for project consoleapp from build.sbt ...
[info] Set current project to consoleapp (in build file:/Users/pradhyo/scala/parent/consoleapp/)
[info] running consoleapp 
[error] (run-main-0) java.lang.ClassNotFoundException: consoleapp
[error] java.lang.ClassNotFoundException: consoleapp
[error]     at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
[error] stack trace is suppressed; run last Compile / bgRunMain for the full output
[error] Nonzero exit code: 1
[error] (Compile / runMain) Nonzero exit code: 1
[error] Total time: 1 s, completed 18-Dec-2019 1:50:06 PM
pradhyo
  • 157
  • 1
  • 2
  • 19
  • @LuisMiguelMejíaSuárez I've edited more information into the post – pradhyo Dec 18 '19 at 18:56
  • 1
    It seems you do not have any scala files in your project... ?! At least there is no `consoleapp` object found, nor any other file suitable as a main class. – cbley Dec 18 '19 at 20:13
  • I would recommend you to create a little git repo with your code and publish it here. – Luis Miguel Mejía Suárez Dec 18 '19 at 20:24
  • Yes, that is the exact same problem I encountered. The existing project was a couple of years old (still in development of course) using scala `2.11.7` even. I wouldn't work because of the scala version , which I couldn't bump because it was inheritance system , so I never managed to make it work because of that ,even though I got every recommendation to use Metals I was left quite disappointed by it. – amer Dec 19 '19 at 08:16
  • @amer I was going to recreate the issue with a small git repo over the weekend. How are you sure it is because of the Scala version? Do you know which of the commands I ran is the correct one? – pradhyo Dec 19 '19 at 18:53
  • @cbley I do have Scala files and a consoleapp object.. will try to reproduce the issue in a brand new setup and update with GitHub link over the weekend – pradhyo Dec 19 '19 at 18:55
  • @pradhyo sbt run .. I think I found somewhere on the Metals page supported versions for plugin and 2.11 wasn't one – amer Dec 19 '19 at 19:40

2 Answers2

3

After following the instructions in the Scala Metals VSCode Readme, use a launch configuration similar to this for the Eclipse screenshots in the question.

.vscode/launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "scala",
            "name": "Debug consoleapp",
            "request": "launch",
            "mainClass": "consoleapp",
            "buildTarget": "consoleapp",
            "args": [],
            "jvmOptions": ["-J-Dconfig.file=/path/to/config/file"]
        }
    ]
}

I had trouble passing the config file for pureconfig correctly. Here's the Github issue with the correct jvmOptions line.

patridge
  • 26,385
  • 18
  • 89
  • 135
pradhyo
  • 157
  • 1
  • 2
  • 19
0

Metals supports these Scala versions 2.13.0, 2.13.1, 2.12.8, 2.12.9, 2.12.10, 2.12.7 and 2.11.12

This is something I noticed from their documentation(doc). So it could pinpoint to your and mine problem which I addressed in comments.

Your scalaVersion := "2.12.3" is not listed here.

amer
  • 1,528
  • 1
  • 14
  • 22
  • I updated my post now - I had bumped up my scala version to 2.12.10 but still got the same error. I undid the changes as they didn't work and posted later so copied the original code and forgot to make the change to the scalaVersion line. But I am not sure if the scala version is causing the issues with the sbt commands - if my understanding is correct, I need to find the external command to run my project and configure VS Code to use it and this step has nothing to do with metals. – pradhyo Dec 23 '19 at 05:28