Maven:对资源子集启用过滤的正确方法

发布于 2024-11-03 02:54:00 字数 1660 浏览 0 评论 0原文

考虑这个目录结构:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

堇年纸鸢 2024-11-10 02:54:00

这个怎么样:

   <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
      </resource>
      <resource>
        <directory>src/main/resources/subdir</directory>
        <targetPath>${project.build.OutputDirectory}/subdir</targetPath>
        <filtering>true</filtering>
        <includes>
          <include>**/*</include>
        </includes>
      </resource>
    </resources>
   </build>

What about this:

   <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
      </resource>
      <resource>
        <directory>src/main/resources/subdir</directory>
        <targetPath>${project.build.OutputDirectory}/subdir</targetPath>
        <filtering>true</filtering>
        <includes>
          <include>**/*</include>
        </includes>
      </resource>
    </resources>
   </build>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文