首页 > 解决方案 > 未找到 Gradle DSL 方法:更新到 Gradle 5.2.1 后的“destination()”

问题描述

更新到 Gradle 5.2.1 后,我的构建失败并出现以下错误:

Gradle DSL method not found: 'destination()'

我发现这个错误与我的analysis.gradle

我的analysis.gradle长相是这样的

apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'jacoco'

jacoco {
toolVersion = "0.7.7.201606060606"
}

check.dependsOn 'checkstyle', 'pmd', 'lint'

task checkstyle(type: Checkstyle) {
println "----- checkstyle -----"
configFile file(projectDir.getAbsolutePath() + '/analysis/checkstyle-ruleset.xml')

source 'src'
source '../domain/src'
source '../util/src'
include '**/*.java'
exclude '**/gen/**'
exclude '**/java-gen/**'
exclude '**/androidTest/**'
exclude '**/test/**'

ignoreFailures = true

classpath = files()

reports {
    xml {
        destination buildDir.absolutePath + "/outputs/reports/checkstyle_report.xml"
    }
}

}

我想我必须更换destination标志,但我不知道如何更换它。

标签: gradleandroid-gradle-pluginbuild.gradle

解决方案


在 Gradle 5.0 之前,该方法setDestination(Object file)已被弃用,请参见此处:setDestination(Object file)

在 Gradle 5.x 中,此方法已被删除,您现在必须使用setDestination(File file)File参数的方法(请参阅setDestination(File file)

因此,您需要将代码更改为:

reports {
    xml {
        destination file("$buildDir/outputs/reports/checkstyle_report.xml")
    }
}

推荐阅读