Maven & Scala: Add source folder to Eclipse Project

EDIT:
You don’t need to do the things described here if you’re also using Scala. In this case, you can switch to the m2eclipse-scala integration which automatically adds the Scala source folder (beside some other useful things).

Just solved one another annoying problem:
Everytime i had to clean my maven-eclipse-project with “mvn eclipse:clean” and re-created the project, i had to manually re-add the “src/test/scala”-folder to the eclipse project.
Now i found a way to tell maven additional source folders to integrate into the eclipse project: the build-helper-plugin.

So to add my src/test/scala-folder permanently i added the following plugin-configuration to my pom.xml (i also had to add the source) :

<!-- ================== MAVEN BUILDER PLUGIN =================== -->
<plugins>
(...)
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>1.1</version>
  <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>
(...)
</plugins>

Wonderful plugin. You can add infinite source folders to your project.
I will surely need it again, when i’m adding the next programming language to my project :-D

This entry was posted in General and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Andreas Pieber
    Posted 4. January 2011 at 07:52 | Permalink

    Ha, this was exactly what I was looking for :) Thank you very much for sharing this!

One Trackback

  1. [...] because you can fix missing source-folders with the Maven Build Helper Plugin as i described here] Now that the project is in your workspace, you see that Eclipse shows some errors, and that [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>