2011年7月28日木曜日

sbteclipseを使ってxsbt(sbt 0.10系)からeclipse用の設定ファイルを作成する方法

Scalaの作者であるMartin Oderskyさんがinetrviewにて
I personally switched to the Eclipse plugin after 20 years of emacs. Certainly before then, I tried the plugin; but for the complex projects I do, it didn't live up to what I needed. Now, I would now never go back to emacs.
『eclipseのScalaプラグインの出来が素晴らしくて、20年使ってきたけどemacsにはもう戻れません!』
という発言をされていたのでeclipseのScalaプラグイン『Scala IDE for Eclipse』が気になってきまして。

でもscalaにはsbtという素敵なビルドツールがあるし、
  • eclipseはエディタとして使う
  • sbtはビルド用に使う
ということができないかなーと思って、sbtとeclipseの連携方法を調査したのでメモ。

参考リンク。

→sbtecipseを使って、sbtから.projectファイルや.classpathファイルを生成するとのこと。

http://stackoverflow.com/questions/6566470/how-to-add-sbteclipse-plugin-to-sbt-0-10-x
→バージョンの指定方法を参考にしました。


やり方。

  1. build.sbtファイルをproject/plugins配下に作成(デフォルトで存在?)。
    ※sbtを実行したルートディレクトリに作成しても良い模様。
  2.  下記内容を記載。
  3. resolvers += {
      val typesafeRepoUrl = new java.net.URL("http://repo.typesafe.com/typesafe/releases")
      val pattern = Patterns(false, "[organisation]/[module]/[sbtversion]/[revision]/[type]s/[module](-[classifier])-[revision].[ext]")
      Resolver.url("Typesafe Repository", typesafeRepoUrl)(pattern)
    }
    
    libraryDependencies <<= (libraryDependencies, sbtVersion) { (deps, version) => 
      deps :+ ("com.typesafe.sbteclipse" %% "sbteclipse" % "1.2" extra("sbtversion" -> version))
    }
    
  4. ※2011/11/05更新
    resolvers += Classpaths.typesafeResolver
    
    addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse" % "1.4.0")
    
  5.  sbtを起動。 sbteclipseのダウンロードが行われる。 
  6. eclipse create-srcを実行すると、.projectファイルと.classpathファイルが作成される。
  7. eclipseにて、.projectファイルが存在するパスを指定し、プロジェクト毎import。
という感じです。

    0 件のコメント:

    コメントを投稿