Overriding Gradle Runtime classpath for custom task


(Serafim Karparov) #1

Hello,

I’m trying to develop a simple task that uses a library which has dependency to log4j. However, when executing my task the build fails with “java.lang.NoSuchMethodError: org.apache.log4j.Logger.getAppender(Ljava/lang/String;)Lorg/apache/log4j/Appender;”. From what I found this is because the Gradle Runtime classpath is taken with higher priority than the one for my custom task. This means that log4j-over-slf4j(part of the gradle runtime) has high prio in the classpath and as it does not contain a method getAppender(String) for the Logger class the build fails.

Is there a way to prevent this behavior and make my task use the log4j implementation for the Logger class?

Thanks, Serafim


(Peter Niederwieser) #2

The best solution is to use a version of the library that uses a compatible Log4J version, or to patch the library. Otherwise you may have to resort to class loader hacks (e.g. run the code in a custom class loader that uses a parent-last strategy).


(Serafim Karparov) #3

Thanks for the reply.

Looks like I’m hitting http://issues.gradle.org/browse/GRADLE-1715