Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle exclude SLF4J from Spring

Well, the following code works but it does not really look good. I have a Spring Boot project and I want to exclude SLF4J because I would like to use Log4j2 instead.

Does anyone know how to improve the code?

dependencies {
    compile("org.springframework:spring-context") {
        exclude module: "spring-boot-starter-logging"
        exclude module: "logback-classic"
    }
    compile("org.springframework.boot:spring-boot-starter-web") {
        exclude module: "spring-boot-starter-logging"
        exclude module: "logback-classic"
    }
    compile("org.springframework.boot:spring-boot-starter-data-mongodb") {
        exclude module: "spring-boot-starter-logging"
        exclude module: "logback-classic"
    }
    compile("org.springframework.boot:spring-boot-starter-log4j2")
    providedRuntime("org.apache.tomcat.embed:tomcat-embed-jasper")
    testCompile("junit:junit")
}
like image 789
Max Peterson Avatar asked Feb 15 '15 12:02

Max Peterson


1 Answers

You can e.g. try:

dependencies {
    [
        "org.springframework:spring-context",
        "org.springframework.boot:spring-boot-starter-web",
        "org.springframework.boot:spring-boot-starter-data-mongodb",
    ].each { dep ->
        compile(dep) {
            exclude module: "spring-boot-starter-logging"
            exclude module: "logback-classic"
        }
    }
    compile("org.springframework.boot:spring-boot-starter-log4j2")
    runtime("org.apache.tomcat.embed:tomcat-embed-jasper")
    testCompile("junit:junit")
}
like image 187
Opal Avatar answered Nov 15 '22 11:11

Opal