# How can I isolate against the Gradle runtime dependencies?

**URL:** <https://discuss.gradle.org/t/how-can-i-isolate-against-the-gradle-runtime-dependencies/6974>\
**Category:** Old Forum Archive\
**Created:** [November 4, 2011, 2:53pm UTC](https://discuss.gradle.org/t/how-can-i-isolate-against-the-gradle-runtime-dependencies/6974 "2011-11-04T14:53:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmuschko1](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bmuschko1/32/7194_2.png) [@bmuschko1](https://discuss.gradle.org/u/bmuschko1)\
**Post date:** [November 4, 2011, 2:53pm UTC](https://discuss.gradle.org/t/how-can-i-isolate-against-the-gradle-runtime-dependencies/6974/1 "2011-11-04T14:53:00Z")

</div>

Hi,

In one of my plugins I have to create my own ClassLoader to make sure I do not include the runtime libraries that Gradle already provides (to avoid library version conflicts). The plugin is written in Groovy so I do want to include the provided Groovy library to be able to actually run the plugin code. To get the available library I use the following code:

```gradle
ClassPathRegistry classPathRegistry = new DefaultClassPathRegistry()
URL[] runtimeClasspath = classPathRegistry.getClassPathUrls('GRADLE_RUNTIME')

```

This works fine in milestone 3 but not in milestone 5. I haven’t had a look at the Gradle code yet but I guess the variable GRADLE\_RUNTIME is not available anymore. This is the error I get:

```gradle
Cause: unknown classpath 'GRADLE_RUNTIME' requested.

```

I could work around this by requiring users to include a Groovy library in the classpath but this feels kind of clunky. In general I think this question is part of a bigger discussion around the fact that Gradle should provide its own ClassLoader for plugins out-of-the-box which should be addressed at some point of time. For now I’d be interested what the recommended way is to get a reference to Gradle’s runtime classpath (optimally compatible in any milestone version of 1.0).

Thanks,

Ben

---

<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:** [November 5, 2011, 1:30am UTC](https://discuss.gradle.org/t/how-can-i-isolate-against-the-gradle-runtime-dependencies/6974/2 "2011-11-05T01:30:00Z")

</div>

Have you tried with parent-last class loader delegation? That would be better than relying on Gradle internals.

---

<div class="post-metadata">

**Author:** ![bmuschko1](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bmuschko1/32/7194_2.png) [@bmuschko1](https://discuss.gradle.org/u/bmuschko1)\
**Post date:** [November 5, 2011, 2:39pm UTC](https://discuss.gradle.org/t/how-can-i-isolate-against-the-gradle-runtime-dependencies/6974/3 "2011-11-05T14:39:00Z")

</div>

I haven’t tried that yet but will certainly give it a shot.

---

<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:** [November 17, 2011, 3:52am UTC](https://discuss.gradle.org/t/how-can-i-isolate-against-the-gradle-runtime-dependencies/6974/4 "2011-11-17T03:52:00Z")

</div>

Did my suggestion work?

---

<div class="post-metadata">

**Author:** ![adammurdoch](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/adammurdoch/32/17_2.png) [@adammurdoch](https://discuss.gradle.org/u/adammurdoch)\
**Post date:** [November 17, 2011, 6:06am UTC](https://discuss.gradle.org/t/how-can-i-isolate-against-the-gradle-runtime-dependencies/6974/5 "2011-11-17T06:06:00Z")

</div>

In milestone 5, your plugins are isolated from the Gradle internals. You should not have to do anything special.

---

<div class="post-metadata">

**Author:** ![bmuschko1](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bmuschko1/32/7194_2.png) [@bmuschko1](https://discuss.gradle.org/u/bmuschko1)\
**Post date:** [November 17, 2011, 11:30am UTC](https://discuss.gradle.org/t/how-can-i-isolate-against-the-gradle-runtime-dependencies/6974/6 "2011-11-17T11:30:00Z")

</div>

@Peter: Sorry, I haven’t found the time to work on this yet. I will have a look at this on the weekend though.

@Adam: I am not sure if I understand this correctly. How does milestone 5 behave if you wrote your plugin in Groovy? Will you have to apply the Groovy plugin to your project to make this work? Does this mean that all plugins have their own ClassLoader by default?

---

<div class="post-metadata">

**Author:** ![adammurdoch](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/adammurdoch/32/17_2.png) [@adammurdoch](https://discuss.gradle.org/u/adammurdoch)\
**Post date:** [November 17, 2011, 7:21pm UTC](https://discuss.gradle.org/t/how-can-i-isolate-against-the-gradle-runtime-dependencies/6974/7 "2011-11-17T19:21:00Z")

</div>

No, you wouldn’t have to apply the Groovy plugin. Groovy is considered part of the Gradle API, so is visible. Even if it weren’t you’d declare it a dependency of your plugin, and it would be included in the plugin classloader.

The plugins that you declare in a buildscript { } section all live in the classloader for that build script, so they’re not yet isolated from each other. The only visible change we’ve made so far is to isolate build scripts + custom plugins from Gradle’s core and plugin implementations. Isolating plugins from each other is yet to happen.

---

<div class="post-metadata">

**Author:** ![bmuschko1](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bmuschko1/32/7194_2.png) [@bmuschko1](https://discuss.gradle.org/u/bmuschko1)\
**Post date:** [November 24, 2011, 3:16pm UTC](https://discuss.gradle.org/t/how-can-i-isolate-against-the-gradle-runtime-dependencies/6974/8 "2011-11-24T15:16:00Z")

</div>

Thanks, that explains it pretty well. I got rid of my dependency to Gradle internals.
