# Overriding Gradle Runtime classpath for custom task

**URL:** <https://discuss.gradle.org/t/overriding-gradle-runtime-classpath-for-custom-task/4740>\
**Category:** Old Forum Archive\
**Created:** [June 20, 2013, 2:35pm UTC](https://discuss.gradle.org/t/overriding-gradle-runtime-classpath-for-custom-task/4740 "2013-06-20T14:35:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serafim\_Karparov](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@Serafim\_Karparov](https://discuss.gradle.org/u/Serafim_Karparov)\
**Post date:** [June 20, 2013, 2:35pm UTC](https://discuss.gradle.org/t/overriding-gradle-runtime-classpath-for-custom-task/4740/1 "2013-06-20T14:35:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [June 20, 2013, 4:26pm UTC](https://discuss.gradle.org/t/overriding-gradle-runtime-classpath-for-custom-task/4740/2 "2013-06-20T16:26:00Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Serafim\_Karparov](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@Serafim\_Karparov](https://discuss.gradle.org/u/Serafim_Karparov)\
**Post date:** [June 21, 2013, 8:17am UTC](https://discuss.gradle.org/t/overriding-gradle-runtime-classpath-for-custom-task/4740/3 "2013-06-21T08:17:00Z")

</div>

Thanks for the reply.

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