Plugin less-asset-pipeline does not appear to compile less files to css in WAR build

322 views
Skip to first unread message

Steve Hole

unread,
Nov 24, 2016, 12:49:17 PM11/24/16
to Grails Dev Discuss
We have run into a problem when deploying an application as a WAR file to an AWS Elastic Beanstalk Tomcat container. Any Less resources defined in the project are NOT compiled into CSS and placed in the WAR file. Neither are they rendered as CSS on demand from the WAR file (no surprise there). Any reference to the generated CSS file comes back as HTTP 404 (no surprise there either). We have verified that it happens in any naked Tomcat container as well. 

The application is building in Grails 3.2.2 and using the following plugin combination:

Gradle Plugins:
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.11.6"

Grails Plugins:
compile "com.bertramlabs.plugins:asset-pipeline-grails:2.11.6"
compile "com.bertramlabs.plugins:less-asset-pipeline:2.11.6"

The versions listed above are latest-and-greatest, but we have tried several different versions back to 2.8.2.  You can recreate this behaviour in any new application by doing the following:

1. Create a new empty app with grails create-app.
2. Add the plugins defined above.
3. Replace the application.css file created by Grails with an application.less file. You can put whatever you like inside as long as it is valid Less (which includes literal CSS).
4. Do a run-app and validate that your less file is processed running in development mode and the default Grails UI is properly rendered.
5. Generate a WAR file from the project and deploy to any valid Tomcat instance and validate that your "application.css" file that should have been compiled from application.less is not there.

At this point is starts to look like a bug, but I'm surprised that others haven't run into this. Also, we are not entirely sure how it is supposed to work after reviewing the code. We presumed that that when the "grails prod war" command was issued that it should compile static CSS files that would show up in the build/assets directory alongside the other assets, but we only get the original an name mangled versions of the Less files. We have tried turning off the development runtime support in build.gradle so that resources are compiled and held statically:

assets {
minifyJs = true
minifyCss = true
developmentRuntime = false
}

No joy.

At this point we presume there is something wrong with the gradle plugin that makes it not compile to static CSS files, but that just may be a misunderstanding of how it is supposed to work. Perhaps it still compiles the Less files on at runtime on demand but permanently retains and returns the compiled version from that point when running from a WAR with developmentRuntime = false. We believe that we should be seeing the compiled CSS files in build/assets because of the following statement in the Grails Asset Pipeline doc:

Precompiling for Production

Assets are now automatically precompiled into target/assets when you create a war file. This should further simplify the deployment process. During WAR creation, only the changed assets are compiled making your precompiler phase a bit quicker. If, for any reason, you want to ensure a clean assets folder, feel free to run grails asset-clean.

During WAR build your assets are also minified using Closure Compiler.


Any insight on this is much appreciated. It is a show stopper for us at the moment and we need to get this resolved or dump our support for Less.


Steve Hole

unread,
Nov 24, 2016, 1:05:05 PM11/24/16
to Grails Dev Discuss
An additional note on this. Everything works as expected when doing a run-app from Grails, a boot-run in Gradle/Eclipse. It only happens when running a naked WAR file manually deployed to a Tomcat instance.

Robson Oliveira

unread,
Mar 21, 2017, 3:20:44 PM3/21/17
to Grails Dev Discuss
Hi, did you get this error? I have the same problem.

Steve Hole

unread,
Mar 23, 2017, 9:55:30 AM3/23/17
to Grails Dev Discuss
Yes, we did figure it out. I posted the answer in detail in our original question. In summary for those reading this thread however, the behaviour is caused by not including the less-asset-pipeline plugin in the gradle plugin build dependency block. You have to put the plugin in both the gradle AND the application dependency blocks. In the application dependency block, you need to list it as an "asset" dependency rather than "runtime" or "compile".

The documentation on this is quite sparse ... and openly contradictory in some places. A result of several versions of support I'm sure. I've been meaning to go back and update the Grails doc to clarify this and just keep forgetting. Hopefully this is enough for you to move forward.
Reply all
Reply to author
Forward
0 new messages