Fork me on GitHub

About

The LessCSS Compiler is a Java library which compiles Less source files to the CSS code.

From Less website:
Less is a CSS pre-processor, meaning that it extends the CSS language, adding features that allow variables, mixins, functions and many other techniques that allow you to make CSS that is more maintainable, themable and extendable.

Compatibility

The compiler is compatible with version 1.7.5. The library is based on the official Less JavaScript compiler adapted to the Rhino engine.

Restrictions:

  • cannot fetch sources from Internet, e.g. @import (less) "http://example.org/style.less"

Requirements

The compiler to run requires:

  • Java 5.0 or higher
  • Third-Party Dependencies (see list)

Download

You can download the library from this page or using various dependency management tools.

Concept

The idea for the LessCompilerImpl class was based on the lesscss-java library by Marcel Overdijk.

Usage

How to compile a source file:

// create compiler & source file
LessCompiler compiler = new LessCompilerImpl();
File source = new File("/less/file.less");

// compile file with default options
String cssCode = compiler.compile(source); 

// set custom option: minify CSS code
CompilerOptions options = new CompilerOptionsBuilder().setMinified(true).create();
String cssMinifiedCode = compiler.compile(source, options);