Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Benefits of maven default filters directory [closed]

Tags:

java

maven

Recently I have discovered maven resource filtering and saw one note in documentation:

Standard Directory Layout
src/main/filters Resource filter files

I have noticed that maven does not search files declared in <filter> tag in this directory by default. So what are the benefits of sticking with Maven Layout in this case (except structure uniformity ofcourse)?

like image 947
user3177112 Avatar asked Mar 14 '16 13:03

user3177112


1 Answers

Basically you're assuming that the files that are present in src/main/filters (or src/test/filters) are themselves filterable. That assumption isn't correct.

The purpose of the src/main/filters folder is to contain the resource filter files that will be used by Maven during the filtering action.

For instance, imagine that you have the following property defined:

<project>
...
<properties>
    <my.property>foo</my.property>
</properties>
...
</project>

And now imagine that you're filtering some folder:

...
<resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
</resource>
...

With that definition, any file inside src/main/resources that contains ${my.property} will be replaced by foo.

Now imagine that you don't want to change your POM every time you want to add a new property.

Then is when src/main/filters comes into action. Instead of placing your properties in your POM, you create a file under src/main/filters with your properties and you add a filter to your POM:

<project>
    ...
    <name>Some Project</name>
    ...
    <build>
        ...
        <filters>
            <filter>my-filter.properties</filter>
        </filters>
        ...
    </build>
    ...
</project>
like image 63
António Ribeiro Avatar answered Nov 15 '22 11:11

António Ribeiro