Maven:对资源子集启用过滤的正确方法
考虑这个目录结构:
src/main/resources/
resource1.properties
subdir/
resource2.properties
我需要 resource2.properties
(及其同级)来经历 Maven 过滤,但宁愿从过滤中排除所有其他资源。
这是一种安全措施:其他属性文件可能包含不应被替换的 ${xxx}
标记。我确实需要保留目标
上的源目录结构。
最后,我发现实现这一目标的唯一方法(以一种不会破坏 maven-eclipse-plugin 的 eclipse:eclipse 的方式)似乎是
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>subdir/**</exclude>
</excludes>
</resource>
<resource>
<!-- 'subdir' resources need placeholder substitution (ie: "filtering") -->
<directory>src/main/resources/subdir</directory>
<targetPath>${project.build.outputDirectory}/subdir</targetPath>
<filtering>true</filtering>
</resource>
</resources>
:脆。这是使用 Maven 2.2.1 和 maven-eclipse-plugin v2.8(最新)。
其他稍微简单的上述版本引发了 maven-eclipse-plugin 的问题,该插件抱怨类似于:
[INFO] 当“过滤”不相同时请求合并。原始=资源src / main /资源:输出=目标/类,包括= [],排除= [subdir / ** | ** / *.java],测试= false,过滤= false,与=资源src /合并main/resources:output=target/classes,include=[subdir/**],exclusion=[**/*.java],test=false,filtering=true
这回想起这个旧线程:那里提到的解决方法有效(降级到 maven-v2.6) eclipse-plugin)但这应该不再需要,因为相关的错误已标记为已修复?
这看起来不像是一个太牵强的用例,但我正在挣扎......
Consider this directory structure:
src/main/resources/
resource1.properties
subdir/
resource2.properties
I need resource2.properties
(and its siblings) to undergo Maven filtering but would rather exclude all other resources from filtering.
This is a safety: other property files may contain ${xxx}
tokens which should not get substituted. I do need to preserve the source directory structure on the target
.
In the end, I found that the only way to achieve this (in a way that doesn't break maven-eclipse-plugin's eclipse:eclipse
) seems to be:
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>subdir/**</exclude>
</excludes>
</resource>
<resource>
<!-- 'subdir' resources need placeholder substitution (ie: "filtering") -->
<directory>src/main/resources/subdir</directory>
<targetPath>${project.build.outputDirectory}/subdir</targetPath>
<filtering>true</filtering>
</resource>
</resources>
You could say this is convoluted and potentially brittle. This is using Maven 2.2.1 with maven-eclipse-plugin v2.8 (latest).
Other, slightly less convoluted versions of the above have triggered issues with maven-eclipse-plugin, which complains with smth similar to:
[INFO] Request to merge when 'filtering' is not identical. Original=resource src/main/resources: output=target/classes, include=[], exclude=[subdir/**|**/*.java], test=false, filtering=false, merging with=resource src/main/resources: output=target/classes, include=[subdir/**], exclude=[**/*.java], test=false, filtering=true
This recalls this old thread: the workaround mentioned there works (downgrading to v2.6 of maven-eclipse-plugin) but this should no longer be required because the related bugs are marked as fixed?
This doesn't look like too far fetched a use case, yet I'm struggling...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个怎么样:
What about this: