Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij scala worksheet can't find project classes

I am unable to get a scala worksheet to find any of my project classes when using Intellij. I have added the new scala worksheet to the src directory of my project as instructed here. However whenever I try to run the worksheet I get the following error

Error:(5, 27) not found: type Order     trait LimitOrder extends Order {                      ^ 

The Order trait is defined in a file included in src/main/scala. I even tried putting the scala worksheet in the src/main/scala and it still fails to find the Order trait.

It appears that the problem goes away if either:

  1. I open an external sbt-console in my project directory. Opening the sbt-console automatically compiles the project sources. Then return to Intellij and re-run the worksheet.
  2. I manually compile the source inside Intellij prior to trying to run the worksheet.

I was under the impression that the worksheet was being compiled on the fly every time I re-run it and thus manually compiling it should be un-necessary. Is this incorrect?

like image 272
davidrpugh Avatar asked Dec 22 '14 07:12

davidrpugh


People also ask

How do I get Scala class in IntelliJ?

In the Project tool window, right-click a Scala library class that you want to decompile. From the context menu, select Decompile Scala to Java. IntelliJ IDEA converts code to Java and opens the converted file in the editor. You can also open the library class in the editor and use its context menu for the conversion.

How do I use worksheets in Scala?

A worksheet is a scala file with . sc extension which you can run and get evaluation results in a special view appeared in the editor. Create worksheet by right-clicking on your Project and choosing 'New' -> 'Scala Worksheet'. Just type your code, press 'Evaluate worksheet' button and results appear.

How do I create a Scala project in IntelliJ?

Delegate a Scala project build to sbtPress Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Build Tools | sbt. In the sbt projects section, select a project for which you want to configure build actions. In the sbt shell section, select the builds option. Click OK to save the changes.


1 Answers

As mentioned in this discussion thread, in order for a worksheet to find changes to your source classes you need to manually check the "Make project" box which will force a recompile of sources prior to running the worksheet.

like image 190
davidrpugh Avatar answered Oct 02 '22 01:10

davidrpugh