How to use maven-resource-plugin to overwrite file

2019-08-31 13:11发布

问题:

I am trying to overwrite one of the files in my project at build time using maven-resource-plugin. I am having multiple profiles in my pom.xml and want to overwrite files base upon the profiles.

My project structure

src/main/java
  -- entity
    SomeClass.java
src/main/resources
  --common-aws
    SomeClass.java
  --common-onprem
    SomeClass.java

So the SomeClass.java inside entity folder has to be replaced by either of the file from common-aws folder or common-onprem folder based on the pom.xml profiles.

I tried below in my pom.xml but it didn't replace the file.

<profile>
.
.
<build>
.
.
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <configuration>
        <encoding>UTF-8</encoding>
    </configuration>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${basedir}/src/main/java/entity</outputDirectory>
                <overwrite>true</overwrite>
                <resources>
                    <resource>
                        <directory>${basedir}/src/main/resources/common-aws</directory>
                        <filtering>true</filtering>
                        <includes>
                            <include>**/*</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>   
.
.
</build>
.
.
</profile>

Is it even possible ? Is there a more logical way of achieving the same thing ?

Maven resouce plugin version - 2.6