How to declare gradle version 5.0 in build.gradle?

Defining a custom wrapper task in your build script has been deprecated since Gradle 4.8 version, see Gradle 4.8 depreciations (section Overwriting Gradle's built-in tasks" section)

Since version 4.8 (and before 5.0) you should have a warning message as below if you still define a custom wrapper task:

$ ./gradlew clean --warning-mode all

> Configure project :

Creating a custom task named 'wrapper' has been deprecated and is scheduled to be removed in Gradle 5.0.

You can configure the existing task using the 'wrapper { }' syntax or create your custom task under a different name.'.

As announced, the support for custom wrapper task has been removed in Gradle 5.0, so you need to use the new way for configuring the Wrapper:

// Configuring the wrapper, the old way (gradle < 4.8 )
// see https://docs.gradle.org/4.4/userguide/gradle_wrapper.html#sec:wrapper_generation
task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
    distributionType = Wrapper.DistributionType.BIN
}

// Configuring the wrapper, the new way (since Gradle 4.8) 
// see https://docs.gradle.org/current/userguide/gradle_wrapper.html#customizing_wrapper
wrapper{
    gradleVersion = '5.1'
    distributionType = Wrapper.DistributionType.BIN
}