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:18

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

Now try again.

查看更多
淡お忘
3楼-- · 2019-01-30 08:19
    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.
查看更多
登录 后发表回答