Wednesday, May 14, 2008

Maven multiple source directories

By default with maven you can only specify a single source directory. Not very flexible. The following pluggin expands this, allowing you to specify many src dirs.

Heres a sample from the pom.xml

<build>


<build>
   <!-- Replaced with build-helper-maven-plugin below to allow for multiple source directories
       <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
   -->
   <testSourceDirectory>
       ${basedir}/src/test/java
   </testSourceDirectory>
   <plugins>
       <plugin>
           <artifactId>maven-compiler-plugin</artifactId>
           <configuration>
               <source>1.5</source>
               <target>1.5</target>
               <debug>false</debug>
           </configuration>
       </plugin>
       <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>
                               ${basedir}/src/main/java
                           </source>
                           <source>
                               ${basedir}/src/types/java
                           </source>
                       </sources>
                   </configuration>
               </execution>
           </executions>
       </plugin>
   </plugins>
</build>

No comments: