每个模块具有不同 logback.xml 的多模块 pom
我有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的模块是一个 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
insrc/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.