Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle task grouping/encapsulation

Tags:

gradle

I am making a simple website and am writing a gradle build script that will do things like lint and minify css/html/js.

At this stage I have just done the CSS which is working, but is just in an initial unstructured format

defaultTasks 'loadToOutput', 'minCSS' ,'deployToSite'

task loadToOutput(type: Copy) {
    from 'src/web'
    into 'output'
}

task compileSCSS(type: Exec) {
    commandLine 'sass', '/home/alistair/dev/personalwebsite/output/style/main.scss', '/home/alistair/dev/personalwebsite/output/style/main.css'
}

task csslint(type: Exec, dependsOn: compileSCSS) {
    def cmdLineOptions = ["--errors=adjoining-classes,box-model,box-sizing,compatible-vendor-prefixes,display-property-grouping,duplicate-background-images,duplicate-properties,empty-rules,errors,fallback-colors,floats,font-faces,font-sizes,gradients,import,important,known-properties,outline-none,overqualified-elements,qualified-headings,regex-selectors,rules-count,shorthand,text-indent,unique-headings,universal-selector,unqualified-attributes,vendor-prefix,zero-units"]
    def cssDir = '/home/alistair/dev/personalwebsite/output/style'

    commandLine = ["csslint"] + cmdLineOptions + [cssDir]
}

task minCSS(type: Exec, dependsOn: csslint) {
    commandLine 'csso', '/home/alistair/dev/personalwebsite/output/style/main.css', '/home/alistair/dev/personalwebsite/output/style/main.css'
}

task deployToSite(type: Copy) {
    from 'output'
    into '/var/www/personalwebsite'
}

What I want to do is group the CSS tasks in a bit of a cleaner way. eg

task CSS {
    compile
    lint
    minify
}

However, the only way I can figure out how to do this is to have a separate build file which contains the CSS project, which is a bit excessive for my current needs. Is there a simple/recommended way I can encapsulate tasks into a group and just execute the group so to speak?

(There are great reference docs on gradle, but very little cookbook/example/best practice info :/)

like image 368
Alistair Avatar asked May 25 '26 22:05

Alistair


1 Answers

The solution:

task CSS(dependsOn: [compile, lint, minify])
like image 59
rodion Avatar answered May 27 '26 12:05

rodion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!