【发布时间】:2018-10-07 16:22:16
【问题描述】:
我有一个 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] 使用 'UTF-8' 编码复制过滤的资源。
[INFO] 复制 2 个资源
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ mma-access-management-auth-server ---
[INFO] 使用 'UTF-8' 编码复制过滤的资源。
[INFO] 复制 5 个资源
这是对的吗?我真的必须排除默认构建的所有资源以避免它们通过默认资源再次复制吗?
【问题讨论】:
-
有点像。插件可以在生命周期中运行多次,甚至可以在同一阶段运行。提示将是您提供的执行 ID:
resources - 如果要替换默认值,则需要使用相同的执行 ID - 如果要将配置放在执行块中。如果有不同的插件,则每个配置的执行都会运行。
标签: maven maven-profiles maven-resources-plugin