Grails
  1. Grails
  2. GRAILS-6980

Plugin layout not found in war when installed from BuildConfig.groovy

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.5
    • Fix Version/s: 2.0-M2
    • Component/s: None
    • Labels:
      None

      Description

      I have a plugin which contains our site layout, which is installed in our host application's BuildConfig.groovy under the plugins section (the only way to do it as it's group id should not be the default org.grails.plugins). I reference this layout in Config.groovy as using 'grails.sitemesh.default.layout' (though the problem is the same when I use '<meta name="layout" content="mypluginlayout" />').

      When I run the host application using 'grails run-app' the layout renders correctly, however when run as a war through 'grails run-war' (or on a standalone Tomcat) it does not. I don't see any obvious error in the logs and the app is deployed correctly, as Spring Security is redirecting me to the login page, as expected. My login page, however, doesn't render properly, as it clearly isn't applying my template.

      I'm not very familiar with grails-core, but looking in GrailsLayoutDecoratorMapper it appear that it looks for the layout in:
      1. /WEB-INF/grails-app/views/layouts/[NAME].gsp
      2. /WEB-INF/plugins/myplugin/grails-app/views/layouts/[NAME].gsp
      3. /WEB-INF/plugins/*/grails-app/views/layouts/[NAME].gsp
      Case 1 doesn't apply as the layout exists only in the plugin. Case 2 & 3 don't find anything, since when I expand my war I can't see a directory under /WEB-INF/plugins for any plugin I have declared in BuildConfig.

      My workaround has been to redeploy my layout plugin with the default org.grails.plugins group and install the old-fashioned way:
      1. Removed the groupId specification from my plugin descriptor.
      2. Repolyed to the Maven repo under the org.grails.plugin group.
      3. Removed the plugin dependency in BuildConfig.groovy from my host app.
      4. Installed the plugin using 'grails install-plugin mylayoutplugin', so that it was installed in application.properties and not BuildConfig.groovy.

      Am I missing anything or is this a bug?

      Thanks,

      Martin Dow.

        Activity

        Hide
        Graeme Rocher added a comment -

        May be a bug, please attach an example that reproduces the problem

        Show
        Graeme Rocher added a comment - May be a bug, please attach an example that reproduces the problem
        Hide
        Martin Dow added a comment -

        Graeme,

        I've attached a tarball containing two Grails projects - one app ('hostapp') and a plugin project containing only a layout ('layoutproject').

        I've installed the maven-publisher plugin to push layoutproject to a local repos, which is set to 'http://localhost:8081/artifactory/plugins-releases-local', so change this in hostapp/grails-app/conf/BuildConfig.groovy' and in 'layoutplugin/grails-app/conf/BuildConfig.groovy' if your repos is installed elsewhere. The group id is set to 'non.defaul.group'.

        Cd into layoutproject to deploy the plugin to your maven repos using 'grails run-app' (to get the maven plugin installed) and 'grails package-plugin && grails maven-deploy --repository=local-repos'

        Now cd into hostapp and run the app using 'grails run-app' - you should see the red message "This layout has been rendered from the plugin. Success.". Everything as expected.

        Restart using 'grails run-war' and this message disappears, as the layout is no longer found. That's the bug I'm talking about.

        Let me know if you need anything else. I'm happy to try and figure out / fix this, so send over any tips you think might point me in the right direction.

        Martin.

        Show
        Martin Dow added a comment - Graeme, I've attached a tarball containing two Grails projects - one app ('hostapp') and a plugin project containing only a layout ('layoutproject'). I've installed the maven-publisher plugin to push layoutproject to a local repos, which is set to 'http://localhost:8081/artifactory/plugins-releases-local', so change this in hostapp/grails-app/conf/BuildConfig.groovy' and in 'layoutplugin/grails-app/conf/BuildConfig.groovy' if your repos is installed elsewhere. The group id is set to 'non.defaul.group'. Cd into layoutproject to deploy the plugin to your maven repos using 'grails run-app' (to get the maven plugin installed) and 'grails package-plugin && grails maven-deploy --repository=local-repos' Now cd into hostapp and run the app using 'grails run-app' - you should see the red message "This layout has been rendered from the plugin. Success.". Everything as expected. Restart using 'grails run-war' and this message disappears, as the layout is no longer found. That's the bug I'm talking about. Let me know if you need anything else. I'm happy to try and figure out / fix this, so send over any tips you think might point me in the right direction. Martin.
        Hide
        Dustin Clark added a comment - - edited

        Sharing some of my lessons learned after experiencing the same exact issue (1.3.7):

        • Double check your HTML source to make sure that your template really isn't being included. Mine was being included, but my CSS/image URLs were wrong (only while running as a war)...so I wrongly assumed that my template wasn't there.
        • Don't use the ui performance tags for referencing your static content...doesn't appear to work, even if the plugin attribute is specified.
        • Don't name your layout main.gsp. You're guaranteed to have conflicts.
        • Don't use absolute=true on your g:resource tags. This doesn't appear to append the pluginContextPath to the absolute url, even if you specify dir="$ {pluginContextPath}

          "

        • Don't use pluginContextPath, as it's no longer required: http://grails.org/doc/latest/guide/single.html#6.3%20Tag%20Libraries (search "Plugin Paths")
        • In your g:resource tags in your plugin layout, make sure you specify the plugin attribute. Set it to the name of your plugin.
        • Move your static images/css from your plugin to a web server. If each application using your plugin has its own copy, your users aren't going to benefit from caching when bouncing between apps.

        EDIT: note that all of the above applies to the layout gsp in your plugin project, not your consuming application.

        Show
        Dustin Clark added a comment - - edited Sharing some of my lessons learned after experiencing the same exact issue (1.3.7): Double check your HTML source to make sure that your template really isn't being included. Mine was being included, but my CSS/image URLs were wrong (only while running as a war)...so I wrongly assumed that my template wasn't there. Don't use the ui performance tags for referencing your static content...doesn't appear to work, even if the plugin attribute is specified. Don't name your layout main.gsp. You're guaranteed to have conflicts. Don't use absolute=true on your g:resource tags. This doesn't appear to append the pluginContextPath to the absolute url, even if you specify dir="$ {pluginContextPath} " Don't use pluginContextPath, as it's no longer required: http://grails.org/doc/latest/guide/single.html#6.3%20Tag%20Libraries (search "Plugin Paths") In your g:resource tags in your plugin layout, make sure you specify the plugin attribute. Set it to the name of your plugin. Move your static images/css from your plugin to a web server. If each application using your plugin has its own copy, your users aren't going to benefit from caching when bouncing between apps. EDIT: note that all of the above applies to the layout gsp in your plugin project, not your consuming application.
        Hide
        Graeme Rocher added a comment -

        works fine in 2.0

        Show
        Graeme Rocher added a comment - works fine in 2.0

          People

          • Assignee:
            Unassigned
            Reporter:
            Martin Dow
          • Votes:
            3 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development