makotan _at_ gmail dot com

なんとなく興味のあるScalaをEclipseとMaven2で使ってみたいなぁと

朝から試行錯誤してみた
とりあえず、ソースコードは書けるようになった
pom.xmlはこんな感じ。長いけどとりあえずコピペすれば良いという状態にしてみた
Scalaと無関係なのもあるけど、それはそれって事で。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>makotan</groupId>
  <artifactId>scala01</artifactId>
  <packaging>jar</packaging>
  <version>0.0.1</version>
  <name>scala01</name>
  <build>
    <sourceDirectory>src/main/scala</sourceDirectory>
    <testSourceDirectory>src/test/scala</testSourceDirectory>
    <defaultGoal>validate</defaultGoal>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <source>1.5</source>
            <target>1.5</target>
            <encoding>UTF-8</encoding>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <configuration>
            <updateReleaseInfo>true</updateReleaseInfo>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
          <execution>
            <id>source-jar</id>
            <phase>package</phase>
            <goals>
            <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <configuration>
          <downloadSources>true</downloadSources>
          <downloadJavadocs>true</downloadJavadocs>
          <!-- 
          <wtpversion>1.5</wtpversion>
          <additionalProjectFacets>
            <sun.facet>9</sun.facet>
          </additionalProjectFacets>
          -->
            <excludes>
              <exclude>org.scala-lang:scala-library</exclude>
            </excludes>
            <additionalBuildcommands>
              <buildCommand>
                <name>ch.epfl.lamp.sdt.core.scalabuilder</name>
              </buildCommand>
              <buildCommand>
                <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
                <triggers>full,incremental,</triggers>
                <arguments>
                  <LaunchConfigHandle>&lt;project&gt;/.externalToolBuilders/org.eclipse.jdt.core.javabuilder.launch</LaunchConfigHandle>
                </arguments>
              </buildCommand>
            </additionalBuildcommands>
            <classpathContainers>
              <buildcommand>org.eclipse.jdt.launching.JRE_CONTAINER</buildcommand>
              <buildcommand>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</buildcommand>
            </classpathContainers>
            <projectnatures>
              <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
              <nature>org.eclipse.jdt.core.javanature</nature>
            </projectnatures>
          </configuration>
      </plugin>
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <scalaVersion>${scala.version}</scalaVersion>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/main/java</source>
              </sources>
            </configuration>
          </execution>
          <execution>
            <id>add-test-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-test-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/test/java</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
    <extensions>
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-webdav</artifactId>
        <version>1.0-beta-2</version>
      </extension>
    </extensions>
  </build>
  <pluginRepositories>
    <pluginRepository>
      <id>scala-tools.org</id>
      <name>Scala-tools Maven2 Repository</name>
      <url>http://scala-tools.org/repo-releases</url>
    </pluginRepository>
  </pluginRepositories>
  <repositories>
    <repository>
      <id>maven.seasar.org</id>
      <name>The Seasar Foundation Maven2 Repository</name>
      <url>http://maven.seasar.org/maven2</url>
    </repository>
    <repository>
      <id>maven-snapshot.seasar.org</id>
      <name>The Seasar Foundation Maven2 SnapShot Repository</name>
      <url>http://maven.seasar.org/maven2-snapshot</url>
      <releases>
      	<enabled>true</enabled>
      </releases>
    </repository>
    <repository>
      <id>dist.codehaus.org</id>
      <name>codehaus Maven2 Repository</name>
      <url>http://dist.codehaus.org/mule/dependencies/maven2/</url>
    </repository>
    <repository>
      <id>scala-tools.org</id>
      <name>Scala-tools Maven2 Repository</name>
      <url>http://scala-tools.org/repo-releases</url>
    </repository>
  </repositories>
  <dependencies>
  </dependencies>
</project>

ここまで終わったら、

mvn eclipse:eclipse

でプロジェクトを生成する
生成終了直後の.projectはこんな感じになってる

<projectDescription>
  <name>scala01</name>
  <comment/>
  <projects/>
  <buildSpec>
    <buildCommand>
      <name>ch.epfl.lamp.sdt.core.scalabuilder</name>
    </buildCommand>
    <buildCommand>
      <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
      <triggers>full,incremental,</triggers>
      <arguments>
        <dictionary>
          <key>LaunchConfigHandle</key>
          <value>&lt;project&gt;/.externalToolBuilders/org.eclipse.jdt.core.javabuilder.launch</value>
        </dictionary>
      </arguments>
    </buildCommand>
    <buildCommand>
      <name>org.eclipse.jdt.core.javabuilder</name>
    </buildCommand>
  </buildSpec>
  <natures>
    <nature>ch.epfl.lamp.sdt.core.scalanature</nature>
    <nature>org.eclipse.jdt.core.javanature</nature>
  </natures>
</projectDescription>

ここからbuildCommandの最後の3行ほど消す

<projectDescription>
  <name>scala01</name>
  <comment/>
  <projects/>
  <buildSpec>
    <buildCommand>
      <name>ch.epfl.lamp.sdt.core.scalabuilder</name>
    </buildCommand>
    <buildCommand>
      <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
      <triggers>full,incremental,</triggers>
      <arguments>
        <dictionary>
          <key>LaunchConfigHandle</key>
          <value>&lt;project&gt;/.externalToolBuilders/org.eclipse.jdt.core.javabuilder.launch</value>
        </dictionary>
      </arguments>
    </buildCommand>
  </buildSpec>
  <natures>
    <nature>ch.epfl.lamp.sdt.core.scalanature</nature>
    <nature>org.eclipse.jdt.core.javanature</nature>
  </natures>
</projectDescription>

この状態にして、eclipseに取り込めばscalajavaも書ける
っていうか、書けることしかまだ確認してないけど忘れそうなのでメモ(笑)
3行消すのを無くさないと気軽にeclipse:eclipseって出来ないんだよね〜どうしよ・・・
つか、ちゃんと動作するのかなぁ〜