This message was deleted.
# plugin-development
s
This message was deleted.
e
yeah that's expected. if the plugin you want to interact with was loaded in a different classpath than your plugin, then its classes are not the same as the ones you expect, even if they have the same name and shape
depends on the use case, but the most straightforward way to prevent these issues is to ensure plugins that interact with each other are loaded in the same classloader
d
So doesn't that basically mean that Gradle plugins can't be composed?
Is it better to use libraries that depend on the Gradle API?
e
I'm not sure what you mean by that
i.e. rather than developing a Gradle plugin, develop a shared library that makes use of Gradle's API and depend on that library in my plugin, rather than using another plugin
e
that doesn't help, if the library is used by multiple plugins that may be loaded in different classloaders it will still cause issues
d
i guess you can use the Worker API with classloader isolation to fix that though?
although it definitely depends on what you're trying to do i guess
i don't think it would fix my problem because i'm trying to register and make use of tooling models
e
only sorta, the interface class still needs to be in the project classloader
if you load plugins (with
apply false
if you don't want them applied there) in a parent project, the same plugins when requested in a child project will be reused from the existing classpath
d
hmmm ok, so the problem here could be that i'm using an init script with
allprojects
to apply the plugin
Oh my gosh that actually worked! I changed my init script from:
Copy code
initscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        classpath("com.opencastsoftware.gradle:gradle-bsp-plugin:%%BSP_PLUGIN_VERSION%%") // this bit gets find & replaced
    }
}

allprojects {
  apply<com.opencastsoftware.gradle.bsp.BspPlugin>()
}
to:
Copy code
initscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        classpath("com.opencastsoftware.gradle:gradle-bsp-plugin:%%BSP_PLUGIN_VERSION%%") // this bit gets find & replaced
    }
}

projectsEvaluated {
    rootProject.subprojects {
        apply<com.opencastsoftware.gradle.bsp.BspPlugin>()
    }
}
and this has resolved the issue for the moment. thanks so much for your help with this!
i gotta say though that this whole thing has got me a little bit spooked about the different ways this could go wrong, depending upon whether users apply the plugin manually, what the structure of their project looks like, etc.
💯 1