How to Learn GrooCSS

  1. Make sure you have the requirements installed.

  2. See below for a simple example using a Groovy script.

  3. Read about the Gradle Plugin.

  4. Read the whole manual to learn about all the features.

  5. Follow me on Twitter.

  6. Star me on github.


  1. JDK 8+

  2. Groovy 2.5+ (or 2.4+ if using 1.0-RC1-groovy2.4)

  3. Gradle 5.x (or 4.8+ if using 1.0-RC1-groovy2.4)

Groovy Script

This example uses Groovy’s @Grab annotation to import GrooCSS. Create a file named "makeCss.groovy" with the following code:

import org.groocss.GrooCSS
// demo
def css = GrooCSS.withConfig { prettyPrint() }.process {
    a { textDecoration 'none' }
    body _.content {
        fontSize 20.px
        width 400.px
        display 'flex'
}.writeTo(new File('main.css'))

Although not recommended, this code would create CSS from the given DSL. Invoke "groovy makeCss.groovy" at the command line to run it. It would output in "main.css" the following:

a {
    text-decoration: none;
body .content {
    font-size: 20px;
    width: 400px;
    display: flex;

Using Gradle without Plugin

I recommend you use GrooCSS with either the Gradle plugin or asset-pipeline, but it can be used by itself.

    import org.groocss.GrooCSS
    buildscript {
        repositories { jcenter() }
        dependencies { classpath 'org.groocss:groocss:1.0-RC1-groovy2.5' }
    task css doLast {
        def file = file('css/out.css')
        GrooCSS.process {
            // DSL goes here

Or using "convert" methods:

    GrooCSS.convertFile('infile.groocss', 'outfile.css')
    GrooCSS.convert(new File('in'), new File('out'))


Go back to Index | Go to Next (Gradle)

Last updated: 31 July 2019