Friday, November 21, 2008

While migrating from ant to Maven 2

Tuesday, February 21, 2006, 16:51
This news item was posted in Java category and has 0 Comments so far.

Few notes I’m taking while migrating one of my project from a classic ant build to Maven 2.

Filtering Source Code



In my ant build, ant preprocesses the source code - meaning it copies it to a temporary folder and while copying its replaces tokens such as “@VERSION@”, “@YEAR@” in the source code header. I found how to filter resources (non java files) with Maven 2 but not how to filter resources. To mimic ant behavior, I reverted to using ant tasks in the Maven 2 description file. Here is how it looks:

    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>process-sources</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <filter token="VERSION" value="${pom.version}"/>
                <filter token="PROJECT.FULLNAME" value="L2FProd.com Common Components"/>
                <filter token="PROJECT.SHORTNAME" value="l2fprod-common"/>
                <filter token="YEAR" value="2005-2006"/>
                <mkdir dir="${basedir}/target/filteredsrc"/>
                <copy filtering="on" todir="${basedir}/target/filteredsrc">
                  <fileset includes="**/*.java" dir="../../src/java/${pom.name}"/>
                </copy>
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>

Then I must change the sourceDirectory attribute of my module to use the filtered sources:

  <build>
    <sourceDirectory>target/filteredsrc</sourceDirectory>
    <resources>

You can leave a response, or trackback from your own site.

Leave a Reply