2012年9月28日金曜日

[Scala] Eclipse に Scala の Maven プロジェクトを インポート

Eclipse に Scala の Maven プロジェクトを m2e を使ってインポートする。

m2eclipse-scala を使う。
これをインストールしておかないと、pom.xml を import するときに、 maven-scala-plugin:2.15.2:compile と testCompile の resolve ができずにエラーになってしまう。


Scala IDE for Eclipse の m2eclipse-scala ページによると、 プロジェクトのインポートや re-configure の際に、
  • add scala nature to project if maven-scala-plugin is used in the pom.xml => add Scala-Library container
  • auto add "src/main/scala" and "src/test/scala"
  • remove of scala-library, scala-compiler, scala-dbc, scala-swing from "Maven Dependencies" Container (under eclipse only, you should not have 2 version of scala-library in the classpath)
  • re-order JRE Container and Scala Container (to avoid scala.ScalaObject NotFound and C° when use "Run As Scala Application")
  • add Scala-tools.org catalog
を自動的にしてくれるらしい。


m2eclipse-scala の設置


Eclipse の Install New Software で アップデートサイトに
http://alchim31.free.fr/m2e-scala/update-site/ を指定する。


Maven Integration for Scala IDE を選択する。Version は 0.4.1。(Meven Integration for Eclipse はインストール済み。)Unsigned content の インストール警告が出るが無視して進む。 インストールが終わったら Eclipse を再起動。


インポートする


Scala プロジェクトの pom.xml を インポートする。

maven-scala-plugin:2.15.2:compile と testCompile が resolve できている。


後処理


インポート後に warning が出る。
More than one scala library found in the build path 
(.../eclipse/configuration/org.eclipse.osgi/bundles/240/2/.cp/lib/scala-library.jar,
.../.m2/repository/org/scala-lang/scala-library/2.9.2/scala-library-2.9.2.jar).
This is not an optimal configuration, 
try to limit to one Scala library in the build path.
Scala library が2つ build path に指定されている。maven-scala-plugin が加えた Scala Container と m2e がpom.xml から加えた Maven Repository 上の scala-library。


Maven dependencies の scala-library は削除できないし、Scala Container を除去すると
The version of scala library found in the build path is
different from the one provided by scala IDE: 2.9.2. 
Expected: 2.9.3-20120703-002906-e3479852a5. 
Make sure you know what you are doing. 
と警告が出てしまう。
2.9.3 を期待されても Sonatype には 2.9.3 なんてないし。
あまり気持ち良くないが、二重ライブラリ問題は放置することにしよう。とりあえず実害はなさそうだし

あとは、「m2e で Eclipse + Maven 環境を作る。」の後処理の手順で JSE の実行環境を 1.5 から Workspace setting にして、Compiler の設定も Workspace デフォルトを使うようにする。

完成。

0 件のコメント:

コメントを投稿