Late evaluation for exclude in tar task

Hi,

I’m trying to create a tar task which will use exclude patterns which have to be computed at execution time rather than configuration time.

What I currently do is:

task myTarTask(type: Tar) {
    def excludePatterns = ... // some computation for exclude patterns
    excludePatterns.each {
        // validate if exclude pattern matches files, if it doesn't throw an exception
    }

    into('...') {
        from '...'
        excludes = excludePatterns
    }

    ...    
}

What I need the task to do is fail the build if the exclude patterns don’t match any files. I want to do this to help developers not messing up their patterns.

This works well as long as the files exist at configuration time. However, sometimes the excluded files aren’t present at configuration time, but will be present at execution time.

Is there a way to accomplish this? If not in a tar task in the build.gradle directly, should I create a custom task (in a plugin) that extends the tar task?

Add a doFirst { ... } action where you do your pattern validation, so it is done in the execution phase as first action and you can fail the task if your validation does not hold.