nas*_*ash 7 filtering properties intellij-idea maven maven-resources-plugin
我有一个问题,当我从Intellij 15.0.2运行Maven构建时,Maven Resources Plugin不会将我的属性过滤到我的文件中.当我mvn compile从Windows命令行运行时,它确实有效.我的插件配置是:
<properties>
<prop1>aaa</prop1>
<prop2>bbb</prop2>
</properties>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>file1</include>
<include>file2</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
tldr:我能够重现你的问题然后通过<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>
Run Code Online (Sandbox Code Playgroud)
未来的读者,如果你只对修复感兴趣,请不要再读了.对于勇敢的SO-er,血淋淋的细节等待下面!
我做了以上操作,因为这是我在以前的项目中打开资源过滤的方式.我不需要更改默认阶段(process-resources),因此根本不需要显式指定maven-resources-plugin.但是,我很想知道为什么OP的配置不起作用,因此resources在maven-resources-plugin 文档中查看mojo 的示例,这些文档似乎<resources>直接指定了<build>.
使用文档中的措辞似乎暗示<resources>仅在copy-resourcesmojo的插件配置下需要配置:
应该从maven-resources-plugin 入门开始,它明确指出:
resources:resources将主源代码的资源复制到主输出目录.
此目标通常自动执行,因为它默认绑定到流程资源生命周期阶段.它始终使用project.build.resources元素指定资源,默认情况下使用project.build.outputDirectory指定复制目标.
我很想暗示Intellij没有错.
使用Intellij 15.0.2时,mvn clean compile从Intellij或命令行执行时,过滤行为(即它是否有效)是相同的.我会认为问题出在插件/ pom配置而不是Intellij本身,除非Intellij的maven集成中存在错误.对于它的价值,我在Intellij中使用maven时已经没有遇到过这个问题(现在从版本12.x开始使用它已经有一段时间了).
你的Intellij是否使用了与命令行使用的mvn不同的捆绑mvn?即从这里和命令行看到maven是否相同?这是我唯一能想到的,除了Intellij的maven整合中的一个错误(不太可能),它可能会解释你所看到的不同行为.
| 归档时间: |
|
| 查看次数: |
3640 次 |
| 最近记录: |