Sunday, July 13, 2008

Multiple source directories with maven2

Without any doubt I can tell that Maven and Maven2 are very powerful project management tool, specially very useful for project building.

As I remember correct in maven1 it had a way to add multiple source directories , however when I switch to maven2 , I found that it does not have support for multiple source directories by default. Recently I got the requirement of adding multiple source directories for WSO2 Registry sample module. That module has few sub directories and I do not need to treat them as module. What I wanted was to add them as source directories in the sample module. So when I do the googling I found a very cool maven pluging called “build-helper-maven-plugin” , which helps us to add multiple source directory to a single module.

Structure of the sample module is as follow;


samples
-- handler-sample
--src
-- filebased-sample
--src
-- wsdl-sample
-- src
-- collection-handler-sample
-- src
-- custom-ui-sample1
-- src

So the corresponding pluging configuration is as follows



<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>handler-sample/src</source>
<source>filebased-sample/src</source>
<source>wsdl-sample/src</source>
<source>collection-handler-sample/src</source>
<source>custom-ui-sample1/src</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

1 comment:

Chathura said...

Cool, this is going to be very useful for implementing samples in WSO2 Registry.