Paul Rivera Paul Rivera - 4 months ago 16
Java Question

Are conditions supported in Maven resource filtering?

I was wondering if there's a way to do

if
-conditions in Maven resource filtering. E.g. something that allows me to do:

somefile.txt:

...
#if($some.project.property == true)
some text to include here
#endif
...


Something similar to velocity.

Answer

Simple answer no. But if you really need conditions you might take a look into the velocity-maven-plugin which solve your problem but it's not intended to filter resources but your use case it might work.

 <plugin>
    <groupId>com.googlecode.velocity-maven-plugin</groupId>
    <artifactId>velocity-maven-plugin</artifactId>
    <version>1.0.0</version>
    <configuration>
            <templateFiles>
                    <directory>/src/main/resources</directory>
                    <includes>
                            <include>*.vm</include>
                    </includes>
            </templateFiles>
            <templateValues>
                    <test>foo</test>
            </templateValues>
    </configuration>
 </plugin>
Comments