Skip to main content

Integrating LESS and Maven

When working on your local workstation, running a local instance of your website is very helpful. I often create two scripts to move code from my development workspace into the local website instance. One takes the war file outputted by Maven and publishes it. The second takes all of my static content and publishes it bypassing Maven, which is much faster than building and deploying the war file.
When integrating CSS preprocessors into the workflow, I need to make sure they run in both deployment scripts. Here are the requirements for running CSS preprpceasors in my build process:
  1. The preprocessors need to run as part of the Maven build so my compiled files make it into the war file.
  2. The preproceasors should be run when I deploy just the static resources to my local instance.
I am going to walk through installing and integrating LESS, but the concept is similar for other tools like compression or inspections.
First I need to install LESS. I am running Ubuntu, so I can simply use the package manager to grab a copy. This is described in several other places already, so I'm not going to go through the process here. Check Tilap TechBlog for an overview.
Now that it's installed, I write a short script to take the CSS files and apply LESS to them. In my case I am also applying the YUI compression that is built into LESS. You'd need to change some of the paths and names in the script for your project. My less files all roll up into "transit.less" so it's the only one I need to explicitly expand.
Now we can call it from Maven using the execution plugin.
Finally, the script needs to be wired in with my static deployment script. In my case, the static deployment is a shell script similar to the script used to call the LESS processor.
So now both of my deployment workflows use the same CSS preprocessors and render identical CSS. Note the shell scripts do tie me to Linux workstations or Cygwin, which is not a big problem for me since all of my development systems are running Ubuntu.

Comments

Popular posts from this blog

ReactJS, NPM and Maven

I'm just starting to get into working with ReactJS, Facebook's open source rendering framework. My project uses SpringBoot for annotation-driven dependency injection and MVC. I thought it would be great if I could use a bit of ReactJS to enhance the application. If you're looking for a basic conceptual intro, I recommend ReactJS for Stupid People and of course the official documentation  is quite good. In full disclosure, I still have no idea how to do "flux" yet. As an experienced Java backend developer, I'm pretty decent at hacking Maven builds - which is precisely what this blog post is going to be about. First, a word about how React likes to be built. Like many front-end tools, there is a toolkit for the node package manager (NPM). From the command prompt, one might run npm install -g react-tools  which installs the jsx command. The  jsx  command provides the ability to transform JSX syntax into ordinary JavaScript, which is precisely what I want...

AWS S3 versus CloudFront Performance

Yesterday I took Amazon CloudFront for a spin. Creating the CloudFront distribution was pretty simple - the wizard process flowed nicely. I found myself relying on the help text in places, but the most surprising thing was how long it took for the distribution to become enabled. I didn't time it exactly, but I probably spent 45 minutes waiting for my new CloudFront distribution to change from "In Progress" to "Enabled" status. The performance is a bit confusing. Compared to the S3 bucket, I didn't see any improvement in performance in a few tries - in fact, the CloudFront CDN performance was worse than the S3 bucket on its own for my 217 KB image file. I decided to take a larger sample, loading the same image 30 times in Chrome and noting the timing data from the "network" tab in the developer tools. I'm located in Brooklyn, have CloudFront configured for the US/Europe with download mode configured. My S3 bucket is in the US Standard zone, w...

IntelliJ Annotations and Maven

IntelliJ has a code inspection feature that is designed to prevent null pointer exceptions based on static code analysis - actually a kind of interesting idea, and the folks over at IntelliJ have recommended that the annotations be included in the Java SDK in the future. I noticed this feature when I was cleaning up some code today and found a cryptic error message in the IntelliJ code inspection tool: Not annotated method overrides method annotated with @NotNull The community documentation for IntelliJ has a nice explanation of this feature , and there is a Maven repository available. The dependency for version 12 of IntelliJ is the following: <!-- STATIC CODE INSPECTIONS -->  <dependency> <groupId>com.intellij</groupId> <artifactId>annotations</artifactId> <version>12.0</version> </dependency> Adding the @NotNull annotation to my overridden method and to a parameter seems to have cleared up the issue. I'm ...