Gradle 5 API Project.configure: configure 'wrapper' task

I’m using the Gradle API with Gradle 5,

configureTask('wrapper', Wrapper) {
      ...
    }

configureTask is defined to:

project.configure(task, config)

Now this causes the error:
> Cannot add task 'wrapper' as a task with that name already exists.

I know this has been resolved for groovy scripts as https://stackoverflow.com/a/54741656
However, I’m unclear, how would we redefine the ‘wrapper’ task when the Project api is involved.

Either use:

project.configure(wrapper) {
}

or

wrapper {
}