apache / apache/grails-core

Grails multi-project resource loading problem

Open
#11,014 9 comments 0 reactions 1 assignee Claimed by @ilopmar View on GitHub
info: workaround available
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

Hi guys. I'm trying to create a multi-module project, and I'm getting an issue with grailsResourceLocator.findResourceForURI(...). It seems that resource locator can locate resources only in main application module but not in included plugins, so it always returns 'null'.

### Task List

- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)

### Steps to Reproduce

1. Create a new empty folder for application. Go inside the new folder.
2. Use Grails command: `grails create-app main-app --profile=web`
3. Use Grails command: `grails create-plugin web-plugin --profile=web-plugin`
4. Add **web-plugin** as dependency to **main-app** [build.gradle](https://github.com/RuslanDidyk/grails3-multi-project-build/blob/master/main-app/build.gradle)
5. Create a [controller ](https://github.com/RuslanDidyk/grails3-multi-project-build/blob/master/web-plugin/grails-app/controllers/web/plugin/DemoController.groovy) in _web-plugin/grails-app/controllers folder
6. Create a [taglib ](https://github.com/RuslanDidyk/grails3-multi-project-build/blob/master/web-plugin/grails-app/taglib/HtmlTagLib.groovy)in _web-plugin/grails-app/taglib_ folder
7. Create a [template gsp](https://github.com/RuslanDidyk/grails3-multi-project-build/blob/master/web-plugin/grails-app/views/demo/_demoTemplate.gsp) in _web-plugin/views/demo_ folder
8. Create a [html](https://github.com/RuslanDidyk/grails3-multi-project-build/tree/master/web-plugin/src/main/webapp) _web-plugin/src/main/webapp_ folder
9. Run **web-app** application and navigate to **DemoController**

### Expected Behaviour

**demo.html** was rendered to UI

### Actual Behaviour

Exception is thrown
```
java.lang.reflect.InvocationTargetException: null
at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:211)
at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:188)
at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Error processing GroovyPageView: [views/demo/_demoTemplate.gsp:1] Error executing tag : Cannot get property 'file' on null object
at grails.artefact.controller.support.ResponseRenderer$Trait$Helper.renderViewForTemplate(ResponseRenderer.groovy:599)
at grails.artefact.controller.support.ResponseRenderer$Trait$Helper.render(ResponseRenderer.groovy:344)
at web.plugin.DemoController.index(DemoController.groovy:6)
... 14 common frames omitted
Caused by: org.grails.gsp.GroovyPagesException: Error processing GroovyPageView: [views/demo/_demoTemplate.gsp:1] Error executing tag : Cannot get property 'file' on null object
at org.grails.web.servlet.view.GroovyPageView.createGroovyPageException(GroovyPageView.java:135)
at org.grails.web.servlet.view.GroovyPageView.handleException(GroovyPageView.java:112)
at org.grails.web.servlet.view.GroovyPageView.renderTemplate(GroovyPageView.java:80)
at org.grails.web.servlet.view.AbstractGrailsView.renderWithinGrailsWebRequest(AbstractGrailsView.java:71)
at org.grails.web.servlet.view.AbstractGrailsView.renderMergedOutputModel(AbstractGrailsView.java:55)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at grails.artefact.controller.support.ResponseRenderer$Trait$Helper.renderViewForTemplate(ResponseRenderer.groovy:596)
... 16 common frames omitted
Caused by: org.grails.taglib.GrailsTagException: [views/demo/_demoTemplate.gsp:1] Error executing tag : Cannot get property 'file' on null object
at org.grails.gsp.GroovyPage.throwRootCause(GroovyPage.java:473)
at org.grails.gsp.GroovyPage.invokeTag(GroovyPage.java:415)
at C__grails3_multi_project_build_resources_web_plugin_grails_app_views_demo__demoTemplate_gsp.run(C__grails3_multi_project_build_resources_web_plugin_grails_app_views_demo__demoTemplate_gsp:15)
at org.grails.gsp.GroovyPageWritable.doWriteTo(GroovyPageWritable.java:162)
at org.grails.gsp.GroovyPageWritable.writeTo(GroovyPageWritable.java:82)
at org.grails.web.servlet.view.GroovyPageView.renderTemplate(GroovyPageView.java:76)
... 20 common frames omitted
Caused by: java.lang.NullPointerException: Cannot get property 'file' on null object
at HtmlTagLib$_closure1.doCall(HtmlTagLib.groovy:17)
at org.grails.gsp.GroovyPage.invokeTagLibClosure(GroovyPage.java:439)
at org.grails.gsp.GroovyPage.invokeTag(GroovyPage.java:364)
... 24 common frames omitted
```
### Environment Information

- **Operating System**: Windows 10 Enterprice
- **Grails Version:** 3.3.5
- **JDK Version:** 1.8.0_144-b01
- **Container Version (If Applicable):** n/a

### Example Application

- https://github.com/RuslanDidyk/grails3-multi-project-build

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.