To improve on @anon58192932 answer you can use only gradleVersion and distributionType fields of Wrapper task and don’t need to manually create distributionUrl which is more error prone since you could change gradle version in one place, but not in the other.
task wrapper(type: Wrapper) {
gradleVersion = '4.2'
distributionType = Wrapper.DistributionType.ALL
}
@edit
gradle 4.8+ will produce error for above. Use instead
wrapper {
gradleVersion = '4.2'
distributionType = Wrapper.DistributionType.ALL
}