Best Practice: Where should task incrementality be defined?

Hi,

I have a question related to best practices. Where should task incrementality be defined?

Let’s say we have a custom task class that has no knowledge of the structure of files on the filesystem. However to property define incrementality, the exact directory structure needs to be defined.

So the question is: Should the task incrementality be defined in custom task class or task definition?

class MakeLinux86GfxStaticLibraryTask extends DefaultTask {
    static enum ScaleformBinaryType { RELEASE, SHIPPING, DEBUG }

    ScaleformBinaryType scaleformBinaryType = null

    @TaskAction
    def makeGfx() {
        project.exec {
            workingDir "${project.projectDir}/gfx"

            environment 'CFLAGS',   '-m32'

            commandLine 'ruby', 'make.rb', '--config', scaleformBinaryType.name().toLowerCase()
        }
    }
}

task makeLinux_x86ReleaseGfxStaticLibrary(type: MakeLinux86GfxStaticLibraryTask) {
    scaleformBinaryType = MakeLinux86GfxStaticLibraryTask.ScaleformBinaryType.RELEASE

    inputs.files fileTree(dir: "$projectDir/gfx",         includes: ['*.rb', '*.sjson'])
    inputs.files fileTree(dir: "$projectDir/gfx/gradle",  include:  '*.sh')

    def libpath = "$projectDir/gfx/Lib/linux/makefile/release/"

    outputs.files(["$libpath/libAIR_SCU.a",
                   "$libpath/libAppFramework_OPENGL.a"])
}

task makeLinux_x86ShippingGfxStaticLibrary(type: MakeLinux86GfxStaticLibraryTask) {
    scaleformBinaryType = MakeLinux86GfxStaticLibraryTask.ScaleformBinaryType.SHIPPING

    inputs.files fileTree(dir: "$projectDir/gfx",         includes: ['*.rb', '*.sjson'])
    inputs.files fileTree(dir: "$projectDir/gfx/gradle",  include:  '*.sh')

    def libpath = "$projectDir/gfx/Lib/linux/makefile/shipping/"

    outputs.files(["$libpath/libAIR_SCU.a",
                   "$libpath/libAppFramework_OPENGL.a"])

}

Thanks

It’s almost always the task class (for testability, discoverability, and usability reasons).

For your example, you could extend SourceTask instead of DefaultTask and then do something like:

task makeLinux_x86ReleaseGfxStaticLibrary(type: MakeLinux86GfxStaticLibraryTask) {
    scaleformBinaryType = MakeLinux86GfxStaticLibraryTask.ScaleformBinaryType.RELEASE

    source fileTree(dir: "gfx",         includes: ['*.rb', '*.sjson'])
    source fileTree(dir: "gfx/gradle",  include:  '*.sh')

    libraries = [ 'AIR_SCU', 'AppFramework_OPENGL' ]
}

Where libraries is a method in your custom task that automatically builds the list of outputs and source is a method provided by SourceTask.