How to Set Up IntelliJ for Scala Development?

已回答

Apologies for the noob question.

Using IntelliJ Idea community 2022.3.1 to learn Scala development on Ubuntu. Coming from Pychon/C++, this is my first attempt at any JVM based language. The problem is, the IDE shows this warning at the top of an open .scala file, even though I can compile and run the basic hello_world-ish code. 

Further, it does not provide the variable suggestions, error checking (when a class attribute is missing) etc. even though I have installed the scala plugin. 

For more information, here are the OS level components I have installed. 

user@dell-xps ~/s/l/scala_testing> scalac --version
Scala compiler version 3.2.2 -- Copyright 2002-2023, LAMP/EPFL
user@dell-xps ~/s/l/scala_testing> scala --version
Scala code runner version 3.2.2 -- Copyright 2002-2023, LAMP/EPFL
user@dell-xps ~/s/l/scala_testing> javac --version
javac 11.0.17
user@dell-xps ~/s/l/scala_testing> java --version
openjdk 11.0.17 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu222.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu222.04, mixed mode, sharing)

In addition, I am attaching the two following screenshots from file->project structure which I thought may be relevant. 

 

 

Please let me know what other component I need to set up to use the full power of Intellij as a scala IDE (hopefully with all the familiar features I get from pycharm for Python development).

0

Hi,

It seems your  Project  Settings > Libraries has a broken library scala-sdk-2.11.12 :
/usr/share/scala-2.11/lib/scala-parser-combinators.jar

Please check if there is the folder exists in /usr/share/scala-2.11/lib/ .

Also, it seems your project is built by the IntelliJ build system. You may try to use the SBT system when creating a new project, in that case, the Scala library will be automatically be downloaded.

1

No, there is no  /usr/share/scala-2.11 directory in my laptop. This is the output I get when I try to get the scala executable. 

user@dell-xps ~> which scala
/home/barmanroys/.local/share/coursier/bin/scala

Even if I have some version of scala messing things up, how to purge it, to get an uncontaminated scala environment? 

 

 

0

It seems that you've installed them by using Coursier, just uninstall all of them by this command in the shell and reinstall again(according to docs here https://get-coursier.io/docs/cli-install#uninstall):

$ cs uninstall --all

The above command uninstalls cs itself as well! If you need to reinstall it, use the installation instructions again.

The Scala SDK in fact just some jar files and quick commands, you can manually download them from https://github.com/lampepfl/dotty/releases/tag/3.2.2 and pick the scala3-3.2.2.tar.gz file or zip file, then extract to anywhere you like, and add the path of SCALA_DIR/bin to your $PATH env. And in this case you'd like to create the library by your self, you may follow the guide here https://www.jetbrains.com/help/idea/library.html#define-library and add all the jars in to the library.

Personally, if you only need to compile, run, test, and package a Scala project, there is no need to download it by yourself, just create a new project in IDEA and then pick the IntelliJ build system, and then create a new Scala SDK, the file will be automatically downloaded and created with a library.

 

The file is download to ~/.ivy2/cache/org.scala-lang/scala-library/jars .

More info you might read the to docs at https://docs.scala-lang.org/getting-started/index.html .

1

请先登录再写评论。