# Handle unstable external APIs in custom plugin

**URL:** <https://discuss.gradle.org/t/handle-unstable-external-apis-in-custom-plugin/48402>\
**Category:** Help/Discuss\
**Created:** [May 6, 2024, 11:49am UTC](https://discuss.gradle.org/t/handle-unstable-external-apis-in-custom-plugin/48402 "2024-05-06T11:49:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nufan](https://avatars.discourse-cdn.com/v4/letter/n/ecae2f/32.png) [@nufan](https://discuss.gradle.org/u/nufan)\
**Post date:** [May 6, 2024, 11:49am UTC](https://discuss.gradle.org/t/handle-unstable-external-apis-in-custom-plugin/48402/1 "2024-05-06T11:49:35Z")

</div>

I am currently developing a Gradle plugin that interfaces with other plugins which are out of my control. In this context I am facing the issue that those external plugins regularly break their APIs in arbitrary ways and I can not directly influence their versions.

To make life easier for my plugin users I had the idea of providing a stub plugin that just checks the versions of the external plugins and pulls in a compatible version of the actual plugin logic as additional build-time dependency. Now I am struggling with resolving the dependency during the execution of the stub plugin. Despite a lot of trial-and-error I could not find a way to eagerly resolve the logic dependency and add it to the classpath so far. Actually the worker API provides a way to modify the classpath dynamically, but to my understanding this only works within tasks while I would need this functionality also outside of tasks.

Do you have any recommendations on how to implement this functionality? The following thread discusses this topic a bit, but does not provide a solution for my case:

> [@Apply plugin inside a plugin](https://discuss.gradle.org/t/apply-plugin-inside-a-plugin/31906/):
>
> Hello, I have recently created a simple plugin that interfaces with GitVersion. It can be found here: [https://plugins.gradle.org/plugin/com.bisiach.gradle.gitversion-plugin](https://plugins.gradle.org/plugin/com.bisiach.gradle.gitversion-plugin) Now I am creating a new plugin that should incorporate the above plugin and force some of the configuration elements on the project where the plug-in is applied to. I have the basic code for my groovy based plugin, like this package com.bisiach.gradle; import org.gradle.api.Plugin; import org.gradle.api.Project; class…

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [May 6, 2024, 11:45pm UTC](https://discuss.gradle.org/t/handle-unstable-external-apis-in-custom-plugin/48402/2 "2024-05-06T23:45:59Z")

</div>

Just have a class `LogicForPluginXVersion2` and a class `LogicForPluginXVersion3` in your plugin jar and use the according one at runtime.

---

<div class="post-metadata">

**Author:** ![nufan](https://avatars.discourse-cdn.com/v4/letter/n/ecae2f/32.png) [@nufan](https://discuss.gradle.org/u/nufan)\
**Post date:** [May 7, 2024, 10:44am UTC](https://discuss.gradle.org/t/handle-unstable-external-apis-in-custom-plugin/48402/3 "2024-05-07T10:44:17Z")

</div>

Thanks for your suggestion. `LogicForPluginXVersion2` and `LogicForPluginXVersion3` then depend on different versions of the external plugin at the compile-time of the custom plugin. How would you handle multiple versions of the same dependency?

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [May 9, 2024, 2:17pm UTC](https://discuss.gradle.org/t/handle-unstable-external-apis-in-custom-plugin/48402/4 "2024-05-09T14:17:25Z")

</div>

In this case probably just simply separate source sets as you didn’t want full feature variants.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [May 9, 2024, 2:18pm UTC](https://discuss.gradle.org/t/handle-unstable-external-apis-in-custom-plugin/48402/5 "2024-05-09T14:18:26Z")

</div>

An alternative would be to use reflection or some dynamic duck-typed language like Groovy.
