Skip to content

Commit 386cd2d

Browse files
author
Dean Wampler
committed
Added notes on issues with IntelliJ
1 parent 5177539 commit 386cd2d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
| April 24, 2021 | Scala `3.0.0-RC3` updates |
2727
| May 15, 2021 | Scala `3.0.0` final updates. Almost done! |
2828
| May 22, 2021 | _Final_ updates for _Programming Scala, Third Edition_! |
29+
| July 24, 2021 | Notes on using IntelliJ |
2930

3031
[![Join the chat at https://gitter.im/deanwampler/programming-scala-book-code-examples](https://badges.gitter.im/deanwampler/programming-scala-book-code-examples.svg)](https://gitter.im/deanwampler/programming-scala-book-code-examples?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
3132

@@ -103,6 +104,23 @@ For other IDEs and text editors, try [Scala Metals](https://scalameta.org/metals
103104

104105
After installing the required plugins, load this project in your IDE, which should detect and use the `sbt` project automatically. For eclipse, run the `sbt eclipse` task to generate project files, then import them.
105106

107+
### Issues with IntelliJ
108+
109+
One reader reported a problem when trying to run examples in IntelliJ: `scalac: Flag -encoding set repeatedly`. I could confirm this problem and I fixed it as follows:
110+
111+
1. Open the preferences ("cmd-," on MacOS)
112+
2. Search for "scala"
113+
3. Select "Build, Execution, Deployment > Compiler > Scala Compiler"
114+
4. Select the "sbt" configuration in the list of Scala build configurations.
115+
5. Select "Additional compiler options:".
116+
6. Remove `-encoding utf-8` from the text, since it is already in the `build.sbt` file.
117+
118+
After that, you should be able to select a type with a `main` and run it.
119+
120+
The same reader also reported errors where multiple occurrences of the same name in a `@targetName` annotation collided. I believe this happens if you use `sbt` in a terminal to compile and then allow IntelliJ to do its own build. There are probably two copies of the class files on the resulting runtime classpath. For example, I saw this error when attempting to run `sbt console` in IntelliJ's `sbt shell`, but not when I used `sbt` in a terminal window.
121+
122+
So, what worked for me was to only use the terminal to run `sbt clean`, then let IntelliJ build the software itself, but when I need to use `sbt console`, I use a terminal window.
123+
106124
### Using Scala Worksheets
107125

108126
If you like working with _Scala worksheets_ in your IDE or editor, you may be able to load any of the REPL "script" files under `src/script` as a worksheet. If your environment is more restrictive, for example about the file extension used, then run the included `bash` script `./make-worksheets.sh` to copy all the REPL "script" examples to worksheet files. This command copies the tree `src/script` to `src/worksheet` and changes the `.scala` extension for all the files to `.worksheet.sc`, the VSCode convention. These behaviors are configurable. Use the `--help` option to see the details. If you are using Windows and you don't have `bash` available, e.g., through the Linux subsystem, then modify individual files as you see fit.

0 commit comments

Comments
 (0)