Skip to content

Latest commit

 

History

History
97 lines (67 loc) · 3.46 KB

README-1.1.md

File metadata and controls

97 lines (67 loc) · 3.46 KB

Gradle LessCss Plugin Build Status

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.

Versions

  • 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.

Usage

Add the plugin

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'
    }
}

Activate the plugin

apply plugin: 'lesscss'

Configure the plugin

lesscss {
    source = fileTree('src/main/less') {
        include 'style.less'
    }
    dest = 'src/main/webapp/assets/css'
    compress = true
    lessVersion = '1.3.3'
}

Run the plugin

The plugin adds two tasks to the build script: lesscss and (implicitly) cleanLesscss.

  • lesscss - compiles the specified LESS files from the source directory to CSS files in the dest directory
  • cleanLesscss - deletes completely the dest 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!

Options

The lesscss object provides 3 properties for configuring the gradle-lesscss-plugin:

  • source (required)
    describes the LESS sources. The fileTree should refer to the LESS base directory ("src/main/less" in the example above), then include will select only the files to be compiled ("style.less" in the example). The value for include 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 compiling style.less results in style.css in the dest directory.

  • compress (optional, defaults to false)
    when set to true turns on compression of the created CSS files.

  • lessVersion (optional, defaults to 1.3.3) set the LESS version for compiler. supported versions are 1.1.3, 1.1.5, 1.3.1, 1.3.2, 1.3.3.

Acknowledgments

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.