Maven资源过滤是否支持条件



我想知道是否有一种方法可以在Maven资源过滤中执行if -条件。例如,某事允许我做:

somefile.txt:

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

和velocity差不多

简单的回答是不。但如果你真的需要条件,你可以看看velocity-maven-plugin,它可以解决你的问题,但它不是为了过滤资源,而是你的用例,它可能会工作。

 <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>

在某些情况下,简单地设置一个属性(每个配置文件)可能很有用。

<yourProperty><![CDATA[
    <your>
        <block>of code</block>
    </your>
    ]]></yourProperty>

如果你不想要这段代码,把属性设置为一个空字符串。

我用这个例子来注入一个<data-source>到我的web.xml开发构建。

最新更新