|
26 | 26 | | April 24, 2021 | Scala `3.0.0-RC3` updates | |
27 | 27 | | May 15, 2021 | Scala `3.0.0` final updates. Almost done! | |
28 | 28 | | May 22, 2021 | _Final_ updates for _Programming Scala, Third Edition_! | |
| 29 | +| July 24, 2021 | Notes on using IntelliJ | |
29 | 30 |
|
30 | 31 | [](https://gitter.im/deanwampler/programming-scala-book-code-examples?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
31 | 32 |
|
@@ -103,6 +104,23 @@ For other IDEs and text editors, try [Scala Metals](https://scalameta.org/metals |
103 | 104 |
|
104 | 105 | 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. |
105 | 106 |
|
| 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 | + |
106 | 124 | ### Using Scala Worksheets |
107 | 125 |
|
108 | 126 | 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