4

I'm getting the stack trace below when I try to launch my app using the Gradle Tomcat plugin's embedded container.

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':tomcatRun'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
...
Caused by: java.lang.ClassCircularityError: java/util/logging/LogRecord
    at net.bull.javamelody.LoggingHandler.publish(LoggingHandler.java:109)
    at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:183)
    at org.apache.juli.logging.DirectJDKLog.debug(DirectJDKLog.java:106)
    at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:369)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:341)
    at org.apache.catalina.startup.Tomcat$start.call(Unknown Source)
    at org.gradle.api.plugins.tomcat.embedded.BaseTomcatServerImpl.start(BaseTomcatServerImpl.groovy:37)
...

It doesn't happen when I use an external Tomcat so I expect it has something to do with Gradle's classpath and Gradle's built-in dependencies (and I don't even know how to find out what those are). I've poked around a bit and people seem to have similar problems relating somehow to SLF4J and/or Logback, neither of which my project uses. I've tried to work around it with the SLF4J legacy bridges but to no avail -- probably because I'm declaring them in my build.gradle and at that point it's too late (Gradle itself has already pulled in / configured SLF4J).

It also looks like it's theoretically possible to disable JULI and make Tomcat log to log4j instead, which seems like it might have a chance of fixing the problem, but the instructions all have to do with manually replacing JARs in $CATALINA_HOME/bin and $CATALINA_HOME/lib, and I don't have the first idea how to make that happen in a Gradle context.

Any ideas?

David Moles
  • 48,006
  • 27
  • 136
  • 235

1 Answers1

3

The easiest fix turns out to be to stop Tomcat from using java.util.logging and have it use Log4J instead.

In my build.gradle:

  tomcat "org.apache.tomcat.embed:tomcat-embed-logging-log4j:${tomcatVersion}"
  // tomcat "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
David Moles
  • 48,006
  • 27
  • 136
  • 235
  • 1
    I know SO discourages "Thanks" comments, but in this case I have to make an exception - THANK YOU! ;-) – vorburger Sep 20 '14 at 15:58