Kotlin-dsl-samples: Gradle wrapper configuration

Created on 9 Jul 2018  路  4Comments  路  Source: gradle/kotlin-dsl-samples

Gradle Wrapper Configuration

Expected Behavior

Ability to configure default gradle wrapper via kotlin DSL

Current Behavior

task<Wrapper>("wrapper") { /**...*/ }

above code spawns warning:
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.'.

wrapper { } 

above doesn't compile with following errors:
Line 45: wrapper {
^ Expression 'wrapper' cannot be invoked as a function. The function 'invoke()' is not found

Line 45: wrapper {
^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public val PluginDependenciesSpec.wrapper: PluginDependencySpec defined in org.gradle.kotlin.dsl

wrapper task with different name (e.g. gradleWrapper) doesn't work well with IntelliJ IDEA. IDEA doesn't not use it to configure the wrapper

Your Environment

Gradle 4.8.1

question superseded

Most helpful comment

tasks.withType<Wrapper> {
    gradleVersion = "4.9"
    // anything else
}

All 4 comments

Accessors aren't generated for tasks, so just doing wrapper {} will fail to compile. The accessors for tasks may be done in https://github.com/gradle/kotlin-dsl/issues/879

To configure an existing task with type do something like the following:

tasks {
  "wrapper"(Wrapper::class) {
    // configuration here
  }
}
tasks.withType<Wrapper> {
    gradleVersion = "4.9"
    // anything else
}
Was this page helpful?
0 / 5 - 0 ratings