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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With