I have this code:
task fatJar(type: Jar) << {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'mvc.MvcMain'
}
baseName = project.name + '-all'
with jar
}
I got this warning:
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. at build_b2xrs1xny0xxt8527sk0dvm2y$_run_closure4.doCall
and this warning:
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
How to rewrite my task?
The line that is essentially causing both of the warnings is
task fatJar(type: Jar) << {
In the Gradle version you are using (which is presumably some 3.x
version, the leftShift
Groovy operator is calling the doLast
method. Everything passed to <<
(leftShift
) is executed in the doLast
task action of that task.
To fix leftShift
deprecation
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
You would want to change your task to:
task fatJar(type: Jar) {
doLast {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'mvc.MvcMain'
}
baseName = project.name + '-all'
with jar
}
}
Now, however, you will still see the other warning:
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.
This warning is telling you that you are modifying the configuration of your fatJar
task at execution time, which is a bad thing to do. It messes upGradle up-to-date checking and incremental builds.
The way to fix this warning, is to follow one of the suggestions from the previous CLI output. For example, here is "configuring the spec during configuration time".
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'mvc.MvcMain'
}
baseName = project.name + '-all'
with jar
}
Notice there is no longer a doLast
block since we aren't adding any different actions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With