Gradle | Spring boot dependencies are not excluded

I am trying to get log4j to work in the project I'm working on. I added the appropriate log4j dependencies to build.gradle and excluded the registration of the Spring starter launch so that it could work.

This worked fine when I used Maven as a build tool, but as soon as I switched to Gradle, it doesn't work at all (except registering with Spring's 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, spring-boot-starter-logging still exists. I guess this is the problem why the log is not working.

Here is 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 is 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 jar file dependency exception. But the log is still not working, log4j.properties is also in the WAR distribution under the classes.

UPDATE 02

The problem worked with my IDE (STS)

+7
spring spring-boot build.gradle gradle log4j
source share
2 answers

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

 configurations { compile.exclude module: 'spring-boot-starter-logging' } 
+23
source share

You excluded the spring-boot-starter-logging module from spring-boot-starter-web, but as you can see from the dependency tree, the spring-boot-starter-data -jpa module also has a dependency on spring-boot-startter-logging, so you should also exclude it from this source (and from all other spring-boot-starter- * dependencies, since they all depend on spring-boot-starter-logging).

+1
source share

All Articles