In grails 4, if I had plugin-A that defined a taglib with static namespace = "someNamespace", I could reference that in controllers in plugin-B via something like:
render someNamespace.sometag()
In grails 4.0.3, plugin-B had a compile dependency on plugin-A, now it has an implementation dependency. Trying to run the same code, now gives the error:
"No such property: someNamespace for class: com.package.PluginBController"
Attempting to use the same namespace in the application that's running with both plugins A and B works just fine, but calling it from a Controller provided by plugin B fails. Are we missing something with the grails 5 upgrade? Does this need to be injected somehow?
You can inject a taglib using its bean name like any other bean but there is no good reason to do that. The technique you show in the question is the recommended approach. We effectively add a namespace variable to your controllers which allow you to invoke tag lib implementations as if they were methods. That approach makes more sense than injecting a taglib.
See the project at https://github.com/jeffbrown/treblataglib.
https://github.com/jeffbrown/treblataglib/blob/8f6d46aa2d227ddb34dfa6adfa50d03b270ddd70/app/grails-app/controllers/app/DemoController.groovy
https://github.com/jeffbrown/treblataglib/blob/8f6d46aa2d227ddb34dfa6adfa50d03b270ddd70/helper/grails-app/taglib/helper/HelperTagLib.groovy
That appears to work:
Output:
EDIT:
A comment below indicates that the problem manifests when a plugin is using a namespaced taglib from another plugin. I have updated the linked project to represent that (https://github.com/jeffbrown/treblataglib/commit/53de85ef7073b8f428ccf0e785097509ed966376).
appdepends onanother-helper,another-helperdepends onhelper.helperprovides a namespaced taglib.DemoControllerinanother-helperuses that namespaced plugin.When run the app using Gradle it seems to work. When I build the war, that seems to work as well.