Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle multi-project with shared logging config

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

like image 322
Hilikus Avatar asked Dec 08 '16 19:12

Hilikus


2 Answers

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

like image 56
Klaus Klein Avatar answered Sep 30 '22 13:09

Klaus Klein


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.

like image 22
dutoitns Avatar answered Sep 30 '22 11:09

dutoitns