Setting wrapper propertiesl in initscript

I am trying to set wrapper properties in an init script for a custom a gradle distribution. This is so that when ‘gradle wrapper’ is run from the custom distribution it will already create the correct distributionUrl in ‘gradle/wrapper/gradle-wrapper.properties’. I am not sure how to go about doing thar as just having

rootProject {
  wrapper { distributionUrl = 'http://foo/bar/....' }
}

fails to execute the initialisation script.

I got this to work, but I don;t know whether it is optimal

rootProject {
    afterEvaluate {
      tasks.getByName('wrapper').distributionUrl = 'xxx'
    }
}

You shouldn’t have to use ‘afterEvaluate {…}’. Have you tried ‘tasks.withType(Wrapper) {…}’?

Thanks Mark, that’s a cleaner solution.