Unable to create Scala class on IntelliJ

ScalaClassIntellij Idea

Scala Problem Overview


I'm just starting to learn Scala. I have installed the Scala plugin for IntelliJ, and created a new Scala project. But when I right-click on the src folder to make a new Scala class, there is no option to do so. Am I missing something?

Scala Solutions


Solution 1 - Scala

Right click on your project, "Add Framework support" and choose Scala framework, then by right click on the packages you can create Scala Class.

After this, right click on src > Mark directory as > Sources Root.

Doing both of these should fix your problem!

Solution 2 - Scala

I figured it out, right click on src > Mark directory as > Sources Root.

Now try again.

Solution 3 - Scala

I just had this issue, also. It turned out that IntelliJ hadn't marked my src/main/scala folder as a "source" folder.

To do this: Project Structure -> Modules -> right click folder and Mark as "Source" (blue)

Similarly the src/main/test folder wasn't marked as a test folder. I was able to add scala classes after those folders were appropriately marked.

Solution 4 - Scala

I had the same problem when I created my first Scala project and I was able to solve it in a simpler way. Click on the "Search everywhere" button and type "sbt", or click directly on the "sbt" button located on the right near the edge of the screen.

sbt button

Now just click on the "Reload all sbt project" button.

reload all sbt project button

This worked for me, I hope it will help someone.

Solution 5 - Scala

Right Click on the SrcScala folder :)

Animation of right-clicking

Solution 6 - Scala

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

Solution 7 - Scala

In IDEA 2016.2.5

From a new SBT or Scala project.

  • Open Project Structure
  • On the Project tab add your JDK (should also be visible in SDKs tab)
  • Under Global Libraries add Scala SDK.

Sadly just adding this to your build.SBT does not impact the IDE behavior.

Solution 8 - Scala

On IntelliJ IDE 2019.1 Ultimate, enable FRAMEWORK Scala like this screens:

enter image description here

enter image description here

enter image description here

Solution 9 - Scala

I had the same problem and what I did is Right Clicked on the Project ---> Then Choose Add Framework Support--> In the Left hand corner there was a list mentioned of Groovy, Kotlin, Maven and Scala.---> From the List I choose Scala but still had issue because the librabry was not specified--->Clicked on Create and it asked me to choose the version as I had Installed 2.11.12, i choose it and it started downloading it. Once it was downloaded I selected Scala and the issue was fixed.

Solution 10 - Scala

Go to Src folder and choose Mark as Directory then choose the option called source root, that would fix your problem.

Solution 11 - Scala

add libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.50" in target -> built.sbt file this works for IntelliJ IDEA 2017

Solution 12 - Scala

  1. Created new gradle project (java)

  2. Add new module "scala" into /src/main/ and "Make Directory" as source ...

  3. added dependencies into build.gradle:

     group 'example-scala'
     version '1.0-SNAPSHOT'
    
     apply plugin: 'java'
     apply plugin: 'scala'
    
     sourceCompatibility = 1.8
    
     repositories {
          mavenCentral()
     }
    
     dependencies {
        compile 'org.scala-lang:scala-library:2.12.6'
        testCompile 'org.scalatest:scalatest_2.11:3.0.5'
        testRuntime 'org.scala-lang.modules:scala-xml_2.11:1.0.6'
        testCompile group: 'junit', name: 'junit', version: '4.12'
    
     } 
    

Solution 13 - Scala

In my case after selecting Sources Root it not shown me any Scala Class option then I choose Generated Sources Root, right click on src > Mark directory as > Generated Sources Root. This worked for me

Solution 14 - Scala

Intellij by default doesn't pick up the dependencies at times. You'll need to create a seperate sbt or maven project and then import it to Intellij.

If you want to create a Java Scala Mixin project you can follow this blog post. And then import it in Intellij.

Or if your just trying to learn Scala.

You can download this maven based Scala Starter Template and import it in intellij and then continuing working on it.

> Note : You might have to specify the sources for the module in the > >Project Structure -> Modules Tab

Solution 15 - Scala

    You can add the scala maven plugin reference in the pom.xml as below 
    
 <build>
    <sourceDirectory>src/main/scala</sourceDirectory>
    <testSourceDirectory>src/test/scala</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <scalaCompatVersion>2.11</scalaCompatVersion>
                    <scalaVersion>2.11.8</scalaVersion>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
    Once you do this and build you will be able to see the option of the scala class.

Solution 16 - Scala

I also faced same issue, the scala file options were not not visible in intellij Idea editor because Scala SDK was not installed. So you get rid of this issue after installing SDK for Scala.

Solution 17 - Scala

Following the below steps resolved for me:

  • Add scala plugin to your Intellij IDE.(Plugins can be added by navigating to File -> settings -> plugins)
  • Enable scala plugin
  • Restart IDE

Solution 18 - Scala

You just need to select the 'Package' instead of 'Project' option from the drop-down menu just above your project name.

Solution 19 - Scala

I experienced this behavior when the folder was not correctly marked as a source folder (blue folder symbol). If that is the case, simply right-click on the whole project and choose Open Module Settings where you can then mark the respective folder as source: Module settings where you may select src as Source folder

Solution 20 - Scala

I had a similar problem and what I did to resolve is just create a package by right clicking on src/main/scala. Once package is created, right click on package and you should be able to find scala class option.

Solution 21 - Scala

In case someone else is having the same problem and the above didn't work, what worked for me was to:

  • Close IntelliJ
  • Delete the .idea folder
  • Open the project

Solution 22 - Scala

It's all about the jdk when creating a project. Click "download" in the corresponding Java selection column and it will select the version for you

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSaurav SircarView Question on Stackoverflow
Solution 1 - ScalaMajicoView Answer on Stackoverflow
Solution 2 - ScalaReddsparkView Answer on Stackoverflow
Solution 3 - ScalaMike PorsView Answer on Stackoverflow
Solution 4 - ScalaDaniele FView Answer on Stackoverflow
Solution 5 - ScalaKeith PinsonView Answer on Stackoverflow
Solution 6 - ScalacwadeevansView Answer on Stackoverflow
Solution 7 - ScalaEric AldingerView Answer on Stackoverflow
Solution 8 - ScalaClaudioView Answer on Stackoverflow
Solution 9 - ScalaChristina SebastianView Answer on Stackoverflow
Solution 10 - ScalaSai MammahiView Answer on Stackoverflow
Solution 11 - Scalatechie95View Answer on Stackoverflow
Solution 12 - ScalaAlexPesView Answer on Stackoverflow
Solution 13 - ScalaGANESH CHOKHAREView Answer on Stackoverflow
Solution 14 - ScalaVishnu667View Answer on Stackoverflow
Solution 15 - ScalaNikunj KakadiyaView Answer on Stackoverflow
Solution 16 - ScalaVishnu Kant TripathiView Answer on Stackoverflow
Solution 17 - Scalasaikumar18View Answer on Stackoverflow
Solution 18 - ScalaNilView Answer on Stackoverflow
Solution 19 - ScalaSusieView Answer on Stackoverflow
Solution 20 - ScalaWaseem HawaldarView Answer on Stackoverflow
Solution 21 - Scalaticot55View Answer on Stackoverflow
Solution 22 - ScalapopolilView Answer on Stackoverflow