I have a maven project where I have defined a profile
based build including a custom maven-resource-plugin
configuration.
...
<profiles>
<profile>
<id>docker</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>resources</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>log4j2*.xml</exclude>
<exclude>docker/*</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
...
Now when I am executing for example mvn compile -P docker
I can see that the resource plugin is executed twice.
INFO] --- maven-resources-plugin:3.1.0:copy-resources (resources) @ mma-access-management-auth-server ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ mma-access-management-auth-server ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5 resources
Is this right? Do I really have to exclude all resources for the default build to avoid that they are copied again through the default-resources?
Do not bind the plugin to the generate-resources phase again. You can change the configuration of the default execution when you use the configuration tag only.
...
<profiles>
<profile>
<id>docker</id>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>log4j2*.xml</exclude>
<exclude>docker/*</exclude>
</excludes>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
...