具有共享日志记录配置的Gradle多项目 [英] Gradle multi-project with shared logging config
问题描述
是否有一种标准方法可以在gradle项目布局中的所有子项目之间共享日志配置(例如,用于log4j或logback)?
Is there a standard way to share a logging config (for log4j or logback for example) across all sub projects in a gradle project layout?
我现在要做的是在每个子项目的src/main/resources
中放置logback.xml
(或log4j.properties
)的副本,但这会导致此配置文件的很多不必要的重复
What I do right now is put a copy of logback.xml
(or log4j.properties
) in src/main/resources
in each sub-project but this results in a lot of unnecessary duplication of this config file
推荐答案
在gradle中使用多个工作集可以轻松解决此问题.
This can be easily overcome using multiple working sets in gradle.
在项目的根目录中添加一个新文件夹,示例"shared-resources"将我们的配置放入其中,然后将以下行简单地添加到子项目的build.gradle
中
Add a new folder in the root of the project, example "shared-resources" put our configs inside it, and simple add the following line to your build.gradle
on the sub-project
sourceSets {
main {
resources {
srcDirs = ["src/main/resource", "../shared-resources"]
}
}
}
这应该将两个文件都添加到您的jar文件中.
This should add both files to your jar file.
可以在 github
这篇关于具有共享日志记录配置的Gradle多项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!