问题
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?
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
回答1:
This can be easily overcome using multiple working sets in 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"]
}
}
}
This should add both files to your jar file.
An example can be find in github
回答2:
Create a shared util
module containing your Log4j2
configuration in its src/main/resources
directory.
Then import the util
module into others.
dependencies {
compile project(":util");
}
I also use the util
module for re-usable Java code, not just for once-off configuration of Log4j2.
来源:https://stackoverflow.com/questions/41046953/gradle-multi-project-with-shared-logging-config