2

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?

Community
  • 1
  • 1
Chief Peter
  • 343
  • 5
  • 11
  • it sort of is. plugins can run several times in the life-cycle and even in the same phase. The hint would be the execution id you give: resources - if you want to replace the default you need to use the same execution id - if you want to place the configuration inside an execution block. If there are different ones the plugin runs per configured execution. – wemu Oct 07 '18 at 17:56

1 Answers1

1

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