Version 3, last updated by David Bernard at Apr 02 19:45 2011 UTC
With Maven CLI
Or how to use maven-eclipse-plugin which emits Eclipse metadata
Assumes:
- Eclipse 3.5 (3.4 should work too)
- Scala IDE for Eclipse plugin 2.7.5.final - 2.8.0 nighly
- Maven 2.2.1 or 3.0 beta1+
Provides:
- Generate Eclipse project files
- Import/refresh generated project files in Eclipse and edit/build/run/debug with no other modifications needed
- Still be able to build/test/run/package using the Maven CLI, independently of Eclipse
The workflow :
- First time
- edit
pom.xml(use instruction from maven-scala-plugin and complete withpom.xmlfragment from below) - run
mvn eclipse:clean eclipse:eclipseto update eclipse meta-data - configure M2_REPO classpath variable (for eclipse) to reference downloaded jar files. This is only needed once for the workspace, not for each project.
- from eclipse :
Window > Preferences > Java > Build Path > Classpath Variableto point to your$HOME/.m2/repositorydirectory - or from shell : run
mvn -Declipse.workspace=<path to workspace> eclipse:configure-workspace( See eclipse:configure-workspace ) to add it automatically.
- edit
- Import project under eclipse (choose `File > Import... > Existing Projects into Workspace)
- after edition of
pom.xml- run
mvn eclipse:clean eclipse:eclipseto update eclipse meta-data - refresh project under eclipse
- run
- code under eclipse
- build the project with maven :
- from command line
- or from eclipse external tools, that call command line
- or from eclipse maven plugin (like m2eclipse)
Configure maven-eclipse-plugin :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<!-- see http://maven.apache.org/plugins/maven-eclipse-plugin/eclipse-mojo.html for more information -->
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<projectnatures>
<projectnature>org.scala-ide.sdt.core.scalanature</projectnature>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
</projectnatures>
<buildcommands>
<buildcommand>org.scala-ide.sdt.core.scalabuilder</buildcommand>
</buildcommands>
<classpathContainers>
<classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER"</classpathContainer>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
</classpathContainers>
<excludes>
<exclude>org.scala-lang:scala-library</exclude>
<exclude>org.scala-lang:scala-compiler</exclude>
</excludes>
<sourceIncludes>
<sourceInclude>**/*.scala</sourceInclude>
<sourceInclude>**/*.java</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>
For more configuration options or information take a look at the site of maven-eclipse-plugin
Configure source folders :
If you have a Scala only project, you need to configure sourceDirectory and testSourceDirectory as is ( required by maven-eclipse-plugin not by maven-scala-plugin ) :
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
...
For more configuration options or information take a look at the site of maven POM Overview (Technical Project Descriptor)
If you have a mixed Java/Scala project with code into separated root directory (like src/(main|test)/scala and src/(main|test)/java) :
<!-- Adds src/main/scala and src/test/scala as source folders, from http://groups.google.com/group/liftweb/browse_thread/thread/3dac7002f9e59546/3918bba2f7a92cd3?pli=1 -->
<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/scala</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/scala</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
For more configuration options or information take a look at the site of build-helper-maven-plugin.
For configuration of the compilation under maven see doc of maven-scala-plugin :
- for scala -depends of->java default configuration should work
- for java -depends of->scala bind 'compile' goal of maven-scala-plugin to phase
process-resources - for inter-dependency java scala (more longer to build because require 2 scalac pass).