Fork me on GitHub

Custom resources filters

You can build your own custom resources filters. Custom resource filter classes implement org.apache.maven.shared.filtering.MavenResourcesFiltering.

Custom Resources Filter Implementation

Custom resource filter classes must be marked as a component with the javax.inject.Named annotation, and are usually also singletons. Below is an example named “itFilter”

@Singleton
@Named("itFilter")
public class ItFilter
    implements MavenResourcesFiltering

Dependency declaration

Your classes must be available in the maven-resources-plugin classpath. This can be done by adding your artifact to the plugin dependencies.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>4.0.0-beta-2</version>
        <configuration>
          ...
        </configuration>
        <dependencies>
          <dependency>
            <groupId>custom resources filters artifact groupId</groupId>
            <artifactId>custom resources filters artifact artifactId</artifactId>
            <version>custom resources filters artifact version</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>

Use of your Custom Resource Filter with the maven-resources-plugin

You must now declare the custom filter in the plugin.

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>4.0.0-beta-2</version>
    <configuration>
      ...
      <mavenFilteringHints>
        <mavenFilteringHint>itFilter</mavenFilteringHint>
      </mavenFilteringHints>
     </configuration>
     ...
   </configuration>
 </plugin>

And that's it!