每个模块具有不同 logback.xml 的多模块 pom

发布于 2025-01-03 01:54:58 字数 147 浏览 3 评论 0原文

我有一个 2 模块 pom,理想情况下我希望每个子模块都有自己的 logback.xml 文件。但是 logback 抱怨在类路径中找到多个 logback.xml 文件。虽然这似乎不是问题并且选择了正确的 xml,但我想知道对此的最佳解决方案是什么。

提前致谢!

I have a 2-module pom and ideally I would like each submodule to have its own logback.xml file. But logback complains about finding more than one logback.xml files in the classpath. Although it seems as if this is not a problem and the right xml is picked up, I would like to know what is the best solution for this.

Thanks in advance!

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

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

发布评论

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

评论(1

倾城°AllureLove 2025-01-10 01:54:58

如果您的模块是一个 jar,要作为另一个模块的依赖项包含在内,那么您实际上不应该有 logback.xml - 由 jar 的用户决定其日志记录配置。您也不应该将 logback 列为依赖项,因为用户应该选择日志记录实现。

我假设你的两个模块之一依赖于另一个。所以依赖的模块应该有logback.xml,而另一个则不应该。

在对每个模块进行单元测试时,您可以将 logback-test.xml 放入 src/test/resources 中,并将 logback 添加为测试范围的依赖项。这样,它就不会被列为模块的依赖项,并且 logback xml 文件也不会被导出。

If your module is a jar, to be included as a dependency by another module, you shouldn't really have a logback.xml - it's up to the user of the jar to decide their logging configuration. Nor should you list logback as a dependency, since the user should choose the logging implementation.

I assume one of your two modules depends on the other. So the dependent module should have the logback.xml, and the other shouldn't.

While unit-testing each module, you can put a logback-test.xml in src/test/resources and add logback as a test-scoped dependency. That way, it won't be listed as a dependency of the module and the logback xml file won't be exported.

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