What Plugin is providing this class?

Issue

  • You are writing a groovy script which uses a particular library, and the script
    is throwing a groovy.lang.MissingMethodException.
  • You are migrating jobs from one Jenkins instance to another. When your job
    runs, you see ‘Unable to resolve class org.foo’.
  • You need to know which library is providing the class you are using.

Environment

Resolution

Jenkins has a complex, modular architecture which means each plugin gets its own ClassLoader which altogether form a hierarchy rooted at the Jenkins core ClassLoader. To locate the plugin which can load a specific class use the following Groovy script:

String className = "<enter fully qualified class name here>"

def clazzResource = className.replaceAll("\\.", "/") + ".class"
println "Looking for: ${clazzResource}\n"
Jenkins.instance.pluginManager.activePlugins.forEach { PluginWrapper plugin ->
    def c = plugin.classLoader.getResources(clazzResource)
    if (c.hasMoreElements()) {
        println "Found in ${plugin}"
        println Collections.list(c).join("\n") + "\n"
    }
}

return

For example, let’s say I would like to know which plugin is providing the snakeyaml
Yaml utilities. Go to the Jenkins Script Console, paste the above script and replace the placeholder like this:

String className = "org.yaml.snakeyaml.Yaml"

You should see something similar as a result:

Looking for: org/yaml/snakeyaml/Yaml.class

Found in Plugin:blueocean-rest-impl
jar:file:/tmp/jenkins/plugins/blueocean-rest-impl/WEB-INF/lib/snakeyaml-1.10.jar!/org/yaml/snakeyaml/Yaml.class

Found in Plugin:kubernetes
jar:file:/tmp/jenkins/plugins/kubernetes/WEB-INF/lib/snakeyaml-1.15.jar!/org/yaml/snakeyaml/Yaml.class

...

References

Dependencies and Class Loading

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.