Unable to create Scala class on IntelliJ

2019-01-30 07:18发布

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?

14条回答
劫难
2楼-- · 2019-01-30 08:04

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.

查看更多
再贱就再见
3楼-- · 2019-01-30 08:07

Right Click on the SrcScala folder :)

Animation of right-clicking "Scala"

查看更多
Summer. ? 凉城
4楼-- · 2019-01-30 08:11

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.

查看更多
女痞
5楼-- · 2019-01-30 08:16

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

查看更多
\"骚年 ilove
6楼-- · 2019-01-30 08:16

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.

查看更多
在下西门庆
7楼-- · 2019-01-30 08:17
  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'
    
    } 
    
查看更多
登录 后发表回答