[Building Sakai] Optional Maven Compilation

Duffy Gillman duffy at rsmart.com
Tue Apr 5 15:29:04 PDT 2011


Hey Steve,

   I haven't followed this all the way through, but it looks like you can use the CodeHaus Build Helper Mojo to accomplish what you want. It has an add-sources goal which allows you to define additional Java source directories. I'm picturing something like:

  src/
     main/
         java/
     stephensCrazyExtraStuff/
         java/

src/main/java would be the <sourceDirectory> for the regular build, and src/stephensCrazyExtraStuff/java would contain your additional/optional Java sources. You can configure the extra directory in the POM using the plugin configuration snippet:

     <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.5</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/stephensCrazyExtraStuff/java</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>

The <sources/> element takes multiple <souce/> child elements, by the way, so you can do this with numerous directories.

You can wrap the entire <plugin> config in a new <profile> and wire up the extra source directory to whatever condition you would like.

Here's the link to the CodeHaus page: http://mojo.codehaus.org/build-helper-maven-plugin/index.html

Please post back your results!

Cheers,

   Duffy Gillman
   Sr. Software Engineer - Sakai CLE
   The rSmart Group, Inc.

On Apr 5, 2011, at 11:19 AM, Steven Githens wrote:

> Hello Dev,
> 
> I poked around in google and some docs but haven't found a way to do 
> this yet.
> 
> I have a few Java files in some of my Sakai stuff I only want to compile 
> if you're using a certain maven profile.  I'm also willing to just 
> manually change the pom.xml file if it's hard to do based on the profile 
> you're compiling with.
> 
> Like, I literally have 1 or 2 *.java files, I just want to exclude from 
> the build.  I was thinking there must be some syntax for this in the 
> <build/> <source/> <excludes/> portion of the files, but haven't gotten 
> it to work yet from trying it out.
> 
> In the past I've just renamed *.java file to *.java_skip, but would like 
> to do this in the pom.xml, without making extra modules.
> 
> Any suggestions?
> 
> Compiled Cheers,
> Steve
> _______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
> 
> TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of "unsubscribe"



More information about the sakai-dev mailing list