Zoltán
Zoltán

Reputation: 22166

IntelliJ Idea Scala files not available in 'New' context menu

I am new to both IntelliJ and Scala. I am attending the course "Functional Programming Principles in Scala" on Coursera. I downloaded the zip file for the sample assignment, which contained a sample Scala project.

I imported the project successfully (I guess) in IntelliJ. However, when I right-click on a package in the project explorer, there are no Scala-related templates. I can only select "New Java class", XML files and some forms.

Does anyone know why this happens and if there is another way to create a new Scala class or object from a template?

Thanks.

Upvotes: 10

Views: 7268

Answers (7)

Anders Eriksson
Anders Eriksson

Reputation: 593

Yes, you need to make the scala directory a source directory (in Menu / Project structure / Modules ) but I also had to do the following:

  1. Still in Project Structure goto Global libraries.
  2. Select Scala SDK.
  3. Right click the Scala SDK and Add to module...

Now my context menu gives me New / Scala class and so on.

Upvotes: 3

Manish
Manish

Reputation: 131

For me it works as following:

Right clicked on src and selected "mark directory as" -> source root.

Upvotes: 9

xeal
xeal

Reputation: 11

Same issue (and solution) as @cwadeevans.

A project named "Week 1" did not show Scala files in the context menu "New". The solution was to delete the project and create a new one named "Week1".

Upvotes: 0

cwadeevans
cwadeevans

Reputation: 141

I had this problem everytime I created a new project with spaces in the name. eg "Hell Wev". Using "HellWev" as a project name seems to work fine

Upvotes: 2

Praphull Purohit
Praphull Purohit

Reputation: 41

Once you've created a project and sbt has finished initializing, try creating another project. It should show up correctly in the new project, as it worked for me. It seems to be some kind of caching issue though Invalidate Caches/Restart didn't help me. Also, ensure that source directories are marked properly (source folders appear in blue color, test sources are in green).

Upvotes: 2

dazito
dazito

Reputation: 7980

This may also be a caching issue. If so, try File then Invalidate Caches / Restart

Upvotes: 4

Zoltán
Zoltán

Reputation: 22166

Import the project by selecting its build.sbt file - not the project folder, not the eclipse project file. Then everything is imported correctly.

Upvotes: 10

Related Questions