CSS Builder Gradle Plugin

The CSS Builder Gradle plugin lets you run the Liferay CSS Builder tool to compile Sass files in your project.

The plugin has been successfully tested with Gradle 4.10.2.

Usage

To use the plugin, include it in your build script:

buildscript {
    dependencies {
        classpath group: "com.liferay", name: "com.liferay.gradle.plugins.css.builder", version: "3.0.0"
    }

    repositories {
        maven {
            url "https://repository-cdn.liferay.com/nexus/content/groups/public"
        }
    }
}

apply plugin: "com.liferay.css.builder"

Since the plugin automatically resolves the Liferay CSS Builder library as a dependency, you have to configure a repository that hosts the library and its transitive dependencies. The Liferay CDN repository hosts them all:

repositories {
    maven {
        url "https://repository-cdn.liferay.com/nexus/content/groups/public"
	}
}

Tasks

The plugin adds one task to your project:

NameDepends OnTypeDescription
buildCSS-BuildCSSTaskCompiles the Sass files in this project.

The plugin also adds the following dependencies to tasks defined by the java plugin:

NameDepends On
processResourcesbuildCSS

The buildCSS task is automatically configured with sensible defaults, depending on whether the java or the war plugins are applied:

Property NameDefault Value
baseDir

If the java plugin is applied: The first resources directory of the main source set (by default: src/main/resources).

If the war plugin is applied: project.webAppDir.

Otherwise: null

BuildCSSTask

Tasks of type BuildCSSTask extend JavaExec, so all its properties and methods, such as args and maxHeapSize, are available. They also have the following properties set by default:

Property NameDefault Value
argsCSS Builder command line arguments
classpathproject.configurations.cssBuilder
defaultCharacterEncoding"UTF-8"
main"com.liferay.css.builder.CSSBuilder"
systemProperties["sass.compiler.jni.clean.temp.dir", true]

Task Properties

Property NameTypeDefault ValueDescription
appendCssImportTimestampsbooleantrueWhether to append the current timestamp to the URLs in the @import CSS at-rules. It sets the sass.append.css.import.timestamps argument.
baseDirFilenullThe base directory that contains the SCSS files to compile. It sets the sass.docroot.dir argument.
cssFilesFileCollection-The SCSS files to compile. (Read-only)
dirNamesList<String>["/"]The name of the directories, relative to baseDir, which contain the SCSS files to compile. All sub-directories are searched for SCSS files as well. It sets the sass.dir argument.
generateSourceMapbooleanfalseWhether to generate source maps for easier debugging. It sets the sass.generate.source.map argument.
importDirFilenullThe META-INF/resources directory of the Liferay Frontend Common CSS artifact. This is required in order to make Bourbon and other CSS libraries available to the compilation.
importFileFileconfigurations.portalCommonCSS.singleFileThe Liferay Frontend Common CSS JAR file. If importDir is set, this property has no effect.
importPathFile-The value of the importDir property if set; otherwise importFile. It sets the sass.portal.common.path argument. (Read-only)
outputDirNameString".sass-cache/"The name of the sub-directories where the SCSS files are compiled to. For each directory that contains SCSS files, a sub-directory with this name is created. It sets the sass.output.dir argument.
outputDirsFileCollection-The directories where the SCSS files are compiled to. Usually, these directories are ignored by the Version Control System. (Read-only)
precisionint5The numeric precision of numbers in Sass. It sets the sass.precision argument.
rtlExcludedPathRegexpsList<String>[]The SCSS file patterns to exclude when converting for right-to-left (RTL) support. It sets the sass.rtl.excluded.path.regexps argument.
sassCompilerClassNameStringnullThe type of Sass compiler to use. Supported values are "jni" and "ruby". If not set, defaults to "jni". It sets the sass.compiler.class.name argument.

The properties of type File support any type that can be resolved by project.file. Moreover, it is possible to use Closures and Callables as values for the int and String properties, to defer evaluation until task execution.

Task Methods

MethodDescription
BuildCSSTask dirNames(Iterable<Object> dirNames)Adds sub-directory names, relative to baseDir, which contain the SCSS files to compile.
BuildCSSTask dirNames(Object... dirNames)Adds sub-directory names, relative to baseDir, which contain the SCSS files to compile.
BuildCSSTask rtlExcludedPathRegexps(Iterable<Object> rtlExcludedPathRegexps)Adds SCSS file patterns to exclude when converting for right-to-left (RTL) support.
BuildCSSTask rtlExcludedPathRegexps(Object... rtlExcludedPathRegexps)Adds SCSS file patterns to exclude when converting for right-to-left (RTL) support.

Additional Configuration

There are additional configurations that can help you use the CSS Builder.

Liferay CSS Builder Dependency

By default, the plugin creates a configuration called cssBuilder and adds a dependency to the latest released version of the Liferay CSS Builder. It is possible to override this setting and use a specific version of the tool by manually adding a dependency to the cssBuilder configuration:

dependencies {
    cssBuilder group: "com.liferay", name: "com.liferay.css.builder", version: "3.0.0"
}

Liferay Frontend Common CSS Dependency

By default, the plugin creates a configuration called portalCommonCSS and adds a dependency to the latest released version of the Liferay Frontend Common CSS artifact. It is possible to override this setting and use a specific version of the artifact by manually adding a dependency to the portalCommonCSS configuration:

dependencies {
    portalCommonCSS group: "com.liferay", name: "com.liferay.frontend.css.common", version: "2.0.1"
}
« Change Log Builder Gradle PluginDB Support Gradle Plugin »
この記事は役に立ちましたか?
0人中0人がこの記事が役に立ったと言っています