跳至主要内容

IntelliJ IDEA 安裝 Scala plugins

這裡僅是紀錄學習與安裝過程,
當作下次環境安裝時的提示。
隨版本異動關步驟可能或有所變動, 必要時在上官網找找吧。畢竟 Scala2 到 Scala3 似乎有大異動,相關 Plugins 也跟著調整

IntelliJ IDEA 安裝 Scala plugins

Create Scala Project(IntelliJ Community Edition)

  • File 🢂 New 🢂 Project
    object Hello extends App {
println("Hello, World!")
}

Scala Worksheet 簡易測試 (REPL)

  1. Right click src and select New 🢂 Scala Worksheet.
  2. Scala Worksheet 命名
  3. coding
  4. run Scala Worksheet

Scala 的 Maven : SBT simple build tool 來建立專案

  • 專案結構
    - .idea (IntelliJ files)
- project (plugins and additional settings for sbt)
- src (source files)
- main (application code)
- java (Java source files)
- scala (Scala source files) <-- This is all we need for now
- scala-2.12 (Scala 2.12 specific files)
- test (unit tests)
- target (generated files)
- build.sbt (build definition file for sbt)
  • 範例程式撰寫
  1. On the Project panel on the left, expand SBTExampleProject 🢂 src 🢂 main
  2. Right-click scala and select New 🢂 Package
  3. Name the package example and click OK.
  4. Right-click the package example and select New 🢂 Scala class.
  5. Name the class Main and change the Kind to object.
  6. Change the code in the class as the following:
    object Main extends App {
val ages = Seq(42, 75, 29, 64)
println(s"The oldest person is ${ages.max}")
}
  • Run
  1. From the Run menu, select Edit configurations
  2. Click the + button and select SBT Task.
  3. Name it Run the program.
  4. In the Tasks field, type ~run. The ~ causes SBT to rebuild and rerun the project when you save changes to a file in the project.
  5. Click OK.
  6. On the Run menu. Click Run ‘Run the program’.
  7. In the code, change 75 to 61 and look at the updated output in the console.

Scala 的測試: ScalaTest#