Maven复制资源执行两次 for profile once default
Maven copy resources executed twice once for profile once default
我有一个 Maven 项目,我在其中定义了一个基于 profile
的构建,包括自定义 maven-resource-plugin
配置。
...
<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>
...
现在当我执行例如mvn compile -P docker
我可以看到资源插件被执行了两次。
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
这样对吗?我真的必须排除默认构建的所有资源以避免通过默认资源再次复制它们吗?
不要再将插件绑定到生成资源阶段。
仅使用配置标签时,可以更改默认执行的配置。
...
<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>
...
我有一个 Maven 项目,我在其中定义了一个基于 profile
的构建,包括自定义 maven-resource-plugin
配置。
...
<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>
...
现在当我执行例如mvn compile -P docker
我可以看到资源插件被执行了两次。
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
这样对吗?我真的必须排除默认构建的所有资源以避免通过默认资源再次复制它们吗?
不要再将插件绑定到生成资源阶段。 仅使用配置标签时,可以更改默认执行的配置。
...
<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>
...