Gradle从Spring中排除SLF4J

时间:2015-02-15 12:14:12

标签: spring logging gradle log4j spring-boot

嗯,以下代码可以正常工作,但它看起来并不好看。我有一个Spring Boot项目,我想排除SLF4J,因为我想改用Log4j2。

有谁知道如何改进代码?

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")
}

1 个答案:

答案 0 :(得分:6)

你可以,例如尝试:

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")
}