Gradle multi-project with shared logging config

 ̄綄美尐妖づ 提交于 2019-12-10 13:45:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!