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.

It supports sources located at:

Requirements

The compiler to run requires:

Concept

The library contains two compilers:

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

Usage

The LessCompiler contains 32 methods. Below is an example of how to use some of them:

String cssCode = null;
LessOptions options = null;

// create compiler
LessCompiler compiler = new LessCompiler();

// compile source code
cssCode = compiler.compileCode(".basic { display: block; }");

// compile source code with custom options
options = new LessOptionsBuilder().ieCompatibilityOff().build();
cssCode = compiler.compileCode(".basic { display: block; }", options);

// compile source file specified by path
cssCode = compiler.compile("http://www.example.org/style.less");

// compile source file
cssCode = compiler.compile(new File("source.less"));

// compile source file specified by path and save CSS code in an output file
compiler.compile("http://www.example.org/style.less", new File("output.css"));

// compile source file and save CSS code in an output file
compiler.compile(new File("source.less"), new File("output.css"));

// compile source file and compress CSS code
cssCode = compiler.compileAndCompress(new File("source.less"));

// compile source file specified by path and compress CSS code using custom encoding
cssCode = compiler.compileAndCompress("http://www.example.org/style.less", Charset.forName("UTF-8"));

// compile source code and generate inline source map
cssCode = compiler.compileCodeWithInlineSourceMap(".basic { display: block; }", new LessOptions());

// compile source file and generate source map (save it in output.map file)
options = new LessOptionsBuilder().sourceMapBasePath("basePath").build();
compiler.compileWithSourceMap(new File("source.less"), new File("output.css"),
                              new File("output.map"), options);

// compile source file specified by path and generate source map (save it in output.css.map file)
compiler.compileWithSourceMap("http://www.example.org/style.less", new File("output.css"), options);

License

The plugin is distributed under open source and commercial friendly "BSD 3-Clause" license:

Copyright (c) 2015, Adam Gabryƛ
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met: 
1. Redistributions of source code must retain the above copyright notice, this 
list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation and/or 
other materials provided with the distribution. 
3. Neither the name of the gabrys.biz nor the names of its contributors may be 
used to endorse or promote products derived from this software without specific 
prior written permission. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Download

You can download the compiler from docs pages or using various dependency management tools:

Example for Maven:

<project>
   ...
   <dependencies>
      <dependency>
         <groupId>biz.gabrys.lesscss</groupId>
         <artifactId>lesscss-compiler2</artifactId>
         <version>2.0.0</version>
      </dependency>
      ...
   <dependencies>
   ...
</project>

Versions

LATEST docs - the newest version under development

List of all available releases: 2.0.0, 1.2.2, 1.2.1, 1.2, 1.1, 1.0.

Version Changelog
2.0.0
(docs)

Features:

  • Set compatibility with Java 8+
  • Added support for HTTP, HTTPS, FTP and classpath protocols
  • Added support for custom protocols (file systems)
  • Added support for Source Maps
  • Added support for custom encodings
1.2.2
(docs)

Bugs:

  • Fixed support for data-uri function
1.2.1
(docs)

Bugs:

  • Fixed quality flaws
1.2
(docs)

Bugs:

1.1
(docs)

Bugs:

  • Fixed quality flaws
1.0
(docs)

Initial release