Reputation: 29816
I want to filter directory and its content based on profile. Here is my pom.xml:
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<targetPath>properties</targetPath>
</resource>
</resources>
<filters>
<filter>src/main/resources/${env}/ucm.properties</filter>
</filters>
</build>
<profiles>
<profile>
<id>int</id>
<properties>
<env>int</env>
</properties>
</profile>
<profile>
<id>uat</id>
<properties>
<env>uat</env>
</properties>
</profile>
<profile>
<id>stag</id>
<properties>
<env>stag</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
And this is my project structure:
But when it is building the jar it is copying all the folders (int, uat, stag, prod) inside it.
How can I solve the issue?
Upvotes: 2
Views: 491
Reputation: 2341
You need to add section in your resource declaration. Like that:
...
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<targetPath>properties</targetPath>
<includes>
<include>${env}/*</include> <!-- including only the associated profile dir -->
<include>env.properties</include>
</includes>
</resource>
...
I don't know if the ${env}
property will work there, else maybe ${project.activeProfiles[0].id}
will work
See http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html for more info
Upvotes: 1