A gradle plugin that compiles LESS files to CSS.
This plugin helps to you to integrate the processing of LESS files into your automated build process without the need of installing node.js on the build server or adding the compiled CSS files to your version control system.
- Version 1.0-1.3.3 of the plugin uses LESS version 1.3.3.
- Version 1.1-1.3.3 of the plugin (not released yet) enables you to choose from LESS versions 1.1.3, 1.1.5, 1.3.1, 1.3.2, 1.3.3.
Add artifact for the plugin to your Gradle buildscript dependencies in your build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'de.obqo.gradle:gradle-lesscss-plugin:1.0-1.3.3'
}
}
apply plugin: 'lesscss'
lesscss {
source = fileTree('src/main/less') {
include 'style.less'
}
dest = 'src/main/webapp/assets/css'
compress = true
lessVersion = '1.3.3'
}
The plugin adds two tasks to the build script: lesscss
and (implicitly) cleanLesscss
.
lesscss
- compiles the specified LESS files from thesource
directory to CSS files in thedest
directorycleanLesscss
- deletes completely thedest
directory (be careful if there are other than generated CSS files in this directory)
You may optionally add a dependency for example for the war
task by specifying
war {
dependsOn 'lesscss'
}
Then everytime the war
task is executed the lesscss
task will be executed before.
That's it!
The lesscss
object provides 3 properties for configuring the gradle-lesscss-plugin:
-
source
(required)
describes the LESS sources. ThefileTree
should refer to the LESS base directory ("src/main/less"
in the example above), theninclude
will select only the files to be compiled ("style.less"
in the example). The value forinclude
might be an Ant-style file pattern (see the section about File trees in the gradle user guide). Note: it is important to correctly set the base directory since all contained files (i.e. imported modules) will be accounted for determining whether the output CSS files are up-to-date or not. -
dest
(required)
describes the target directory for the CSS files. This is either a string or a file object. The names of the generated CSS files are derived from the source files, thus compilingstyle.less
results instyle.css
in thedest
directory. -
compress
(optional, defaults tofalse
)
when set totrue
turns on compression of the created CSS files. -
lessVersion
(optional, defaults to1.3.3
) set the LESS version for compiler. supported versions are1.1.3
,1.1.5
,1.3.1
,1.3.2
,1.3.3
.
Main parts of the build configuration as well as two classes for running JS scripts with Rhino have been taken from Eric Wendelin's great gradle-js-plugin. Without his work the development of this plugin would have taken much longer (or would have possibly not even succeeded). Thanks Eric!
Support for lessVersion
has been added by Alex Ley.