The fix
tldr https://en.wikipedia.org/wiki/Wikipedia:Too_long;_didn%27t_read:我能够重现您的问题,然后通过移出来解决它<resources>
元素从插件配置直接到下面<build>
像这样:
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- <snip> Other plugins -->
</plugins>
</build>
未来的读者,如果您只对修复感兴趣,请不要继续阅读。对于勇敢的 SO-er,血淋淋的细节在下面等待着!
我为什么这么做?
我执行了上述操作,因为这就是我在之前的项目中打开资源过滤的方式。我不需要更改默认阶段(process-resources
),因此不需要明确指定maven-resources-plugin
根本不。然而,我很好奇为什么 OP 的配置不起作用,因此查看了示例resources
maven-resources-plugin 中的 mojo文档 https://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html这似乎有<resources>
直接指定在<build>
.
中的措辞Usage https://maven.apache.org/plugins/maven-resources-plugin/usage.html文档似乎暗示<resources>
仅需要在插件配置下进行配置copy-resources
mojo:
Update
应该从 maven-resources-plugin 开始介绍 https://maven.apache.org/plugins/maven-resources-plugin/index.html其中明确指出:
resources:resources 将主源代码的资源复制到
主输出目录。
这个目标通常会自动执行,因为它受到
默认为进程资源生命周期阶段。它总是使用
project.build.resources 元素来指定资源,并由
默认使用project.build.outputDirectory来指定副本
目的地。
Intellij 的奇怪之处?
我很想认为 Intellij 没有错。
使用 Intellij 15.0.2,执行时过滤行为(即是否有效)是相同的mvn clean compile
从 Intellij 或从命令行。我本以为问题出在插件/pom 配置中,而不是 Intellij 本身,除非 Intellij 的 maven 集成中存在错误。不管怎样,我在 Intellij 中使用 maven 时还没有遇到这个问题(从版本 12.x 开始使用它已经有一段时间了)。
您的 Intellij 使用的捆绑 mvn 是否与命令行使用的 mvn 不同?即,在这里看到的 Maven 和从命令行看到的 Maven 是否相同?那就是only我能想到的,除了 Intellij 的 Maven 集成中的一个错误(不太可能)之外,它可能会解释您所看到的不同行为。