1. 程式人生 > >sbt筆記三 用IDEA和Eclipse開發sbt專案

sbt筆記三 用IDEA和Eclipse開發sbt專案

首先把我們之前的專案hello-sbt複製兩份,分別叫hello-sbt-idea和hello-sbt-eclipse。

新增外掛

有兩個外掛可以把sbt專案轉換為idea專案和eclipse專案。 在hello-sbt-idea/project/下建立plugin.sbt檔案,內容為: ?
1 2 addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.2") // 2013/10/28

同樣的,在hello-sbt-eclipse/project/下建立plugin.sbt檔案,內容為:

?
1 2 addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.4.0") // 2013/10/28
(如果sbt已經在運行了,就reload一下)

匯入專案到IDEA

在hello-sbt-idea/下開啟命令列,執行: $sbt > gen-idea 完成後,專案根目錄下生成了.idea和.idea_modules檔案 啟動IDEA,選擇開啟專案,可以看到idea已經識別出hello-sbt-idea了。

再看一下包結構

根目錄下的project資料夾(圖中選中項)被轉換成一個模組


匯入專案到Eclipse 在hello-sbt-eclipse/下開啟命令列,執行: ?
1 2 $sbt > eclipse
完成後,熟悉的.project和.classpath檔案出現了。 匯入成功