program story

IntelliJ에서 Scala 클래스를 만들 수 없습니다.

inputbox 2020. 8. 29. 11:00
반응형

IntelliJ에서 Scala 클래스를 만들 수 없습니다.


저는 이제 막 스칼라를 배우기 시작했습니다. IntelliJ 용 Scala 플러그인을 설치하고 새 Scala 프로젝트를 만들었습니다. 그러나 새로운 Scala 클래스를 만들기 위해 src 폴더를 마우스 오른쪽 버튼으로 클릭하면 그렇게 할 수있는 옵션이 없습니다. 내가 뭔가를 놓치고 있습니까?


프로젝트를 마우스 오른쪽 버튼으로 클릭하고 " 프레임 워크 지원 추가 "를 선택하고 Scala 프레임 워크를 선택한 다음 패키지를 마우스 오른쪽 버튼으로 클릭하여 Scala 클래스를 만들 수 있습니다.

이 후, 오른쪽 클릭 src> Mark directory as> Sources Root.

이 두 가지를 모두 수행하면 문제가 해결 될 것입니다!


나는 그것을 알아 냈고, src> Mark directory as> Sources Root를 마우스 오른쪽 버튼으로 클릭하십시오.

이제 다시 시도하십시오.


나는 또한이 문제가 있었다. IntelliJ가 내 src/main/scala폴더를 "소스"폴더로 표시하지 않은 것으로 밝혀졌습니다 .

이렇게하려면 Project Structure -> Modules ->폴더를 마우스 오른쪽 버튼으로 클릭하고 Mark as "Source"(파란색)

마찬가지로 src/main/test폴더는 테스트 폴더로 표시되지 않았습니다. 해당 폴더가 적절하게 표시된 후에 스칼라 클래스를 추가 할 수있었습니다.


이름에 공백이있는 새 프로젝트를 만들 때마다이 문제가 발생했습니다. 예 : "Hell Wev". "HellWev"또는 이와 유사한 프로젝트 이름을 사용하면 제대로 작동하는 것 같습니다.


Src Scala 폴더를 마우스 오른쪽 버튼으로 클릭하십시오. :)

"Scala"를 오른쪽 클릭하는 애니메이션


IDEA 2016.2.5에서

새로운 SBT 또는 Scala 프로젝트에서.

  • 프로젝트 구조 열기
  • 프로젝트 탭에서 JDK를 추가합니다 (SDK 탭에도 표시되어야 함).
  • Global Libraries에서 Scala SDK를 추가합니다.

슬프게도 이것을 build.SBT에 추가하면 IDE 동작에 영향을 미치지 않습니다.


Src 폴더로 이동하여 Mark as Directory를 선택한 다음 소스 루트라는 옵션을 선택하면 문제가 해결됩니다.


libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.50"대상에 추가 -> built.sbtIntelliJ IDEA 2017에서 작동하는 파일


  1. 새 Gradle 프로젝트 생성 (Java)
  2. 새 모듈 "scala"를 / src / main /에 추가하고 "Make Directory"를 소스로 추가합니다.
  3. 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'
    
    } 
    

IntelliJ IDE 2019.1 Ultimate에서 다음 화면과 같이 FRAMEWORK Scala를 활성화합니다.

여기에 이미지 설명 입력

여기에 이미지 설명 입력

여기에 이미지 설명 입력


Intellij는 기본적으로 때때로 종속성을 선택하지 않습니다. 별도의 sbt 또는 maven 프로젝트를 만든 다음 Intellij로 가져와야합니다.

Java Scala Mixin 프로젝트를 만들고 싶다면이 블로그 게시물을 팔로우 할 수 있습니다 . 그런 다음 Intellij로 가져옵니다.

또는 스칼라를 배우려는 경우.

이 Maven 기반 Scala Starter Template을 다운로드 하여 intellij로 가져온 다음 계속 작업 할 수 있습니다.

Note : You might have to specify the sources for the module in the

Project Structure -> Modules Tab


    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.

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.


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


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


비슷한 문제가 있었고 해결하기 위해 src / main / scala를 마우스 오른쪽 버튼으로 클릭하여 패키지를 만드는 것입니다. 패키지가 생성되면 패키지를 마우스 오른쪽 버튼으로 클릭하면 스칼라 클래스 옵션을 찾을 수 있습니다.


제 경우에는 Sources Root를 선택한 후 Scala Class 옵션이 표시되지 않은 다음 Generated Sources Root를 선택 하고 src> Mark directory as> Generated Sources Root를 마우스 오른쪽 버튼으로 클릭합니다. 이것은 나를 위해 일했습니다.

참고 URL : https://stackoverflow.com/questions/38006735/unable-to-create-scala-class-on-intellij

반응형