Error with gradle 4.0: You cannot add child specs at execution time

Viewed 2363

I am using this configuration to build a fat jar including all dependencies, but I want to exclude some files from the dependencies:

jar {
    manifest {
        attributes "Main-Class": "$mainClassName"
    }

    doFirst {
        from (configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }) {
            exclude 'META-INF/*'
            exclude 'about.html'
        }
    }
}

With gradle 3.5, I get the following warning message:

Configuring child specs of a copy task at execution time of the task has been deprecated and is scheduled to be removed in Gradle 4.0. Consider configuring the spec during configuration time, or using a separate task to do the configuration.

Since gradle 4.0, this became an error (as announced):

You cannot add child specs at execution time. Consider configuring this task during configuration time or using a separate task to do the configuration.

How can I rewrite the from ... statement (the error message points to that line) to remove the error and get the desired result? Removing the exclude block fixes the error but is not what I want.

0 Answers
Related