"Unable to resolve class" when compiling Jenkins Groovy script

I’m now trying to add these dependencies programmatically - I have a list of plugins in a YAML file elsewhere. Reading the YAML is fine, but how do I then add the dependencies? I’ve tried the method from this thread but it isn’t working. I seem to have the dependencies but now I’m getting my original import error again…