Gradle | Spring引导依赖不排除 [英] Gradle | Spring boot dependencies are not excluding

查看:157
本文介绍了Gradle | Spring引导依赖不排除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让log4j在我正在开发的一个项目中工作。我在build.gradle中添加了相关的log4j依赖项,并排除了Spring引导启动程序日志记录,因此它可以工作。

当我使用Maven作为构建工具时,此工作正常,但是一旦我切换到Gradle,它根本就不工作(除了Spring引导启动器的日志记录外)。这里是我的build.gradle中的依赖关系。

$ p code $ dependency {
compile('org.springframework.boot:spring- ('org.springframework.boot:spring-boot-starter-web'){
排除模块:'org.springframework.boot:spring-boot-start-data-jpa')
compile starter-logging'
}
compile('org.springframework.boot:spring-boot-starter-log4j')
compile('org.springframework.boot:spring-boot-starter- )
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.postgresql:postgresql:9.3-1101-jdbc41')
编译('org.scala-lang:scala-library:2.10.4')
testCompile('org.springframework.boot:spring-boot-starter-test'){
exclude module:' commons-logging'
}
providesCompile('org.springframework.boot:spring-boot-starter-tomcat')
}

但是你可以清楚地看到de审判树 spring-boot-starter-logging 仍然存在。我猜这就是为什么日志记录不起作用的问题。



这里是依赖关系树:

  + --- org.springframework.boot:spring-boot-starter-data-jpa: - > 1.2.1.RELEASE 
| + --- org.springframework.boot:spring-boot-starter:1.2.1.RELEASE
| | + --- org.springframework.boot:spring-boot:1.2.1.RELEASE
| | | + --- org.springframework:spring-core:4.1.4.RELEASE
| | | \ --- org.springframework:spring-context:4.1.4.RELEASE
| | | + --- org.springframework:spring-aop:4.1.4.RELEASE
| | | | + --- aopalliance:aopalliance:1.0
| | | | + --- org.springframework:spring-beans:4.1.4.RELEASE
| | | | | \ --- org.springframework:spring-core:4.1.4.RELEASE
| | | | \ --- org.springframework:spring-core:4.1.4.RELEASE
| | | + --- org.springframework:spring-beans:4.1.4.RELEASE(*)
| | | + --- org.springframework:spring-core:4.1.4.RELEASE
| | | \ --- org.springframework:spring-expression:4.1.4.RELEASE
| | | \ --- org.springframework:spring-core:4.1.4.RELEASE
| | + --- org.springframework.boot:spring-boot-autoconfigure:1.2.1.RELEASE
| | | \ --- org.springframework.boot:spring-boot:1.2.1.RELEASE(*)
| | + --- org.springframework.boot:spring-boot-starter-logging:1.2.1.RELEASE

这是我的log4j.properties文件

  log4j.rootLogger = INFO,fileout,CONSOLE 
PID = ??? ?
LOG_PATTERN = [%d {yyyy-MM-dd HH:mm:ss.SSS}] log4j%X {context} - $ {PID}%5p [%t] ---%c {1}: %m%n


#使用PatternLayout将CONSOLE设置为ConsoleAppender。
log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern = $ {LOG_PATTERN}

#配置文件appender
的配置log4j.category.org.hibernate.validator.internal.util.Version = WARN
log4j.category.org。 apache.coyote.http11.Http11NioProtocol = WARN
log4j.category.org.apache.tomcat.util.net.NioSelectorPool = WARN
log4j.category.org.apache.catalina.startup.DigesterFactory = ERROR

log4j.appender.fileout = org.apache.log4j.RollingFileAppender
log4j.appender.fileout.File = sampleLog.log
log4j.appender.fileout.MaxFileSize = 1024KB
log4j.appender.fileout.MaxBackupIndex = 1
log4j.appender.fileout.layout = org.apache.log4j.PatternLayout
log4j.appender.fileout.layout.conversionPattern = $ {LOG_PATTERN}

更新

我设法解决了jar文件依赖排除问题CY。但是日志记录仍然不起作用,log4j.properties也在类下的WAR分发中。

UPDATE 02

它的问题在于我的IDE(STS) 所有 spring-boot-starter - * 项目都是依赖项目在> spring-boot-starter 项目上,依次依赖于 spring-boot-starter-logging 。我可以通过在配置部分添加以下行来移除此依赖项:

 配置{
compile.exclude模块:'spring-boot-starter-logging'
}


I'm trying to get log4j to work in a project that I'm working on. I added the relevant log4j dependencies in build.gradle and excluded the Spring boot starter logging so it can work.

This worked fine when I used Maven as the build tool, but once I switched to Gradle it's not working at all (excepts the logging from Spring boot starter). Here are the dependencies in my build.gradle

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-web'){
        exclude module: 'org.springframework.boot:spring-boot-starter-logging'
    }
    compile('org.springframework.boot:spring-boot-starter-log4j')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.postgresql:postgresql:9.3-1101-jdbc41')
    compile('org.scala-lang:scala-library:2.10.4')
    testCompile('org.springframework.boot:spring-boot-starter-test') {
        exclude module: 'commons-logging'
    }
    providedCompile('org.springframework.boot:spring-boot-starter-tomcat')
}

But as you can clearly see in the dependency tree the spring-boot-starter-logging is still there. I'm guessing that this is the issue why the logging isn't working.

Here's the dependency tree:

+--- org.springframework.boot:spring-boot-starter-data-jpa: -> 1.2.1.RELEASE
|    +--- org.springframework.boot:spring-boot-starter:1.2.1.RELEASE
|    |    +--- org.springframework.boot:spring-boot:1.2.1.RELEASE
|    |    |    +--- org.springframework:spring-core:4.1.4.RELEASE
|    |    |    \--- org.springframework:spring-context:4.1.4.RELEASE
|    |    |         +--- org.springframework:spring-aop:4.1.4.RELEASE
|    |    |         |    +--- aopalliance:aopalliance:1.0
|    |    |         |    +--- org.springframework:spring-beans:4.1.4.RELEASE
|    |    |         |    |    \--- org.springframework:spring-core:4.1.4.RELEASE
|    |    |         |    \--- org.springframework:spring-core:4.1.4.RELEASE
|    |    |         +--- org.springframework:spring-beans:4.1.4.RELEASE (*)
|    |    |         +--- org.springframework:spring-core:4.1.4.RELEASE
|    |    |         \--- org.springframework:spring-expression:4.1.4.RELEASE
|    |    |              \--- org.springframework:spring-core:4.1.4.RELEASE
|    |    +--- org.springframework.boot:spring-boot-autoconfigure:1.2.1.RELEASE
|    |    |    \--- org.springframework.boot:spring-boot:1.2.1.RELEASE (*)
|    |    +--- org.springframework.boot:spring-boot-starter-logging:1.2.1.RELEASE

Here's my log4j.properties file

log4j.rootLogger=INFO, fileout, CONSOLE
PID=????
LOG_PATTERN=[%d{yyyy-MM-dd HH:mm:ss.SSS}] log4j%X{context} - ${PID} %5p [%t] --- %c{1}: %m%n


# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=${LOG_PATTERN}

# Log4j configurations for with file appender
log4j.category.org.hibernate.validator.internal.util.Version=WARN
log4j.category.org.apache.coyote.http11.Http11NioProtocol=WARN
log4j.category.org.apache.tomcat.util.net.NioSelectorPool=WARN
log4j.category.org.apache.catalina.startup.DigesterFactory=ERROR

log4j.appender.fileout=org.apache.log4j.RollingFileAppender
log4j.appender.fileout.File=sampleLog.log
log4j.appender.fileout.MaxFileSize=1024KB
log4j.appender.fileout.MaxBackupIndex=1
log4j.appender.fileout.layout=org.apache.log4j.PatternLayout
log4j.appender.fileout.layout.conversionPattern=${LOG_PATTERN}

UPDATE

I managed to fix the exclusion of jar file dependency. But the logging is still not working, log4j.properties is also in the WAR distribution under classes.

UPDATE 02

It worked issue is with the my IDE (STS)

解决方案

All the spring-boot-starter-* projects are dependent on spring-boot-starter project, which in turn in dependent on spring-boot-starter-logging. I was able to remove this dependency by adding the following line in configurations section:

configurations {
    compile.exclude module: 'spring-boot-starter-logging'
}

这篇关于Gradle | Spring引导依赖不排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆