使用maven程序集插件覆盖资源文件

发布于 2024-11-07 16:32:14 字数 189 浏览 1 评论 0原文

我使用 maven- assembly-plugin 和“jar-with-dependencies”来打包 jar。有 2 个具有 log-back.xml 的依赖项工件。第二个工件取决于第一个工件。我希望在最终 jar 中包含第二个工件的 log-back.xml,但它始终包含第一个工件的 log-back.xml。那么我该如何控制呢?

谢谢

I use maven-assembly-plugin with "jar-with-dependencies" to package jar. There are 2 dependencies artifact having log-back.xml. The second artifact is depend on the first one. I want to have log-back.xml of the second artifact in final jar, but it always contain log-back.xml of the first one. So how can I control this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

等往事风中吹 2024-11-14 16:32:15

您可以使用 unpackOptions 来实现此目的。尝试如下操作:

<assembly>
...
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>${groupId}:${artifact.whose.logback.is.to.be.excluded} </include>
            </includes>
            <unpack>true</unpack>
            <unpackOptions>
                <excludes>
                    <exclude>**/logback.xml</exclude>
                </excludes>
            </unpackOptions>
        </dependencySet>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <excludes>
                <exclude>${groupId}:${artifact.whose.logback.is.to.be.excluded}</exclude>
            </excludes>
            <unpack>true</unpack>
        </dependencySet>
    </dependencySets>
</assembly>

You can use the unpackOptions to achieve this. Try something like the following:

<assembly>
...
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>${groupId}:${artifact.whose.logback.is.to.be.excluded} </include>
            </includes>
            <unpack>true</unpack>
            <unpackOptions>
                <excludes>
                    <exclude>**/logback.xml</exclude>
                </excludes>
            </unpackOptions>
        </dependencySet>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <excludes>
                <exclude>${groupId}:${artifact.whose.logback.is.to.be.excluded}</exclude>
            </excludes>
            <unpack>true</unpack>
        </dependencySet>
    </dependencySets>
</assembly>
无戏配角 2024-11-14 16:32:15

(此时使用最新版本的 maven- assembly-plugin :3.0.0)

我在程序集构建方面遇到了同样的问题。

我有两个具有相同属性文件但内容不同的依赖项(一个好的,另一个用缺少的声明覆盖第一个)。

问题是我最终用错误的配置文件替换了程序集 jar 中的另一个文件。

我发现覆盖该文件的唯一最干净的解决方案是:

1 - 添加我想在项目中构建时保留的好文件:
例如:src/main/resources/META-INF/services/myfileWhichOverwriteTheBadDependencyRessources.xml

2 - 在我的程序集描述符中添加一个将“filtered”设置为“true”的文件集:(

    <fileSet>
        <directory>${project.main.resources}/META-INF</directory>
        <outputDirectory>META-INF</outputDirectory>
        <filtered>true</filtered>
    </fileSet>

“project.main.xml”)在我的例子中,“resource”属性设置为“src/main/resources”)

(With last version of maven-assembly-plugin at this time : 3.0.0)

I had the same problem with an assembly build.

I had tow dependencies with the same properties file but with a different content (one good and the other overwritting the first with missing declarations).

The problem was that i finally had the bad configuration file replacing the other in my assembly jar.

The only cleanest solution i found to overwrite the file was to :

1 - Add the good file that i wanted to keep for the build in my project :
ex: src/main/resources/META-INF/services/myfileWhichOverwriteTheBadDependenciesRessources.xml

2 - Add a fileset with 'filtered' setted to 'true' in my assembly descriptor :

    <fileSet>
        <directory>${project.main.resources}/META-INF</directory>
        <outputDirectory>META-INF</outputDirectory>
        <filtered>true</filtered>
    </fileSet>

(the 'project.main.resource' property is setted to 'src/main/resources' in my case)

゛时过境迁 2024-11-14 16:32:15

第一个工件是您自己项目的模块吗?如果是这样,您可以排除 pom.xml 的资源部分中的 log-back.xml。

<resources>
  <resource>
    <directory>src/main/resources</directory>
    <excludes>
      <exclude>log-back.xml</exclude>
    </excludes>
  </resource>
  ...
</resources>

然而,只有当该模块在整个 jar 的范围之外构建时,它本身不需要 log-back.xml 时,这才有效。

Is the first artifact a module of your own project? If so, you could exclude the log-back.xml there in the resources section of the pom.xml.

<resources>
  <resource>
    <directory>src/main/resources</directory>
    <excludes>
      <exclude>log-back.xml</exclude>
    </excludes>
  </resource>
  ...
</resources>

However, this only works if this module does not require the log-back.xml by itself when it is built out of the scope of the overall jar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文