Fork me on GitHub

Filtering a source folder

The Templating Maven Plugin filter-sources goal lets you filter a dedicated source folder. In one pass, it filters that folder and adds the resulting filtered folder to the POM model as a source folder.

If, for example, you have some of your code where you would like to reference properties coming from the POM, you want to put those classes inside the sourceDirectory tag.

Please note that filtering the standard src/main/java folder is not supported.

<project>
...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>templating-maven-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>filter-src</id>
            <goals>
              <goal>filter-sources</goal>
            </goals>
                <configuration>              
                  <!-- 
                    Note the two following parameters are the default one. 
                    These are specified here just as a reminder. 
                    But as the Maven philosophy is strongly about conventions, 
                    it's better to just not specify them.
                  -->
                  <sourceDirectory>${basedir}/src/main/java-templates</sourceDirectory>
                  <outputDirectory>${project.build.directory}/generated-sources/java-templates</outputDirectory>
                </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>