【问题标题】:Could not find method destination() for arguments on Report xml of type org.gradle.api.plugins.quality.internal.findbugs.FindBugsXmlReportImpl在 org.gradle.api.plugins.quality.internal.findbugs.FindBugsXmlReportImpl 类型的报告 xml 上找不到参数的方法 destination()
【发布时间】:2019-09-18 22:57:07
【问题描述】:

在将 android studio 版本更新为 3.4.0 后,我将 Gradle 版本更新为 5.1.1 并尝试重建项目,但它在 quality.gradle 文件中引发异常。

 Task failed with an exception.
-----------
* Where:
Script '/home/Desktop/workplace/testProject/quality/quality.gradle' line: 35

* What went wrong:
A problem occurred evaluating script.
> Could not find method destination() for arguments [/home/Desktop/workplace/testProject/app/build/reports/findbugs/findbugs.xml] on Report xml of type org.gradle.api.plugins.quality.internal.findbugs.FindBugsXmlReportImpl.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Android 项目级类路径 URL 和 Gradle 分发 URL

类路径'com.android.tools.build:gradle:3.4.0' distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip

我尝试使缓存无效并重新启动项目。它总是失败

这是我的 quality.gradle 文件

apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'checkstyle'
apply plugin: 'findbugs'
apply plugin: 'pmd'

task checkstyle(type: Checkstyle) {
    configFile file("${project.rootDir}/quality/checkstyle/checkstyle.xml")
    configProperties = [
            'checkstyle.cache.file': rootProject.file('build/checkstyle.cache'),
            'checkstyleSuppressionsPath': file("${project.rootDir}/quality/checkstyle/suppressions.xml").absolutePath
    ]
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
    exclude '**/commons/**' //exclude copied stuff from apache commons
    classpath = files()
}

task findbugs(type: FindBugs) {
    ignoreFailures = false
    effort = "max"
    reportLevel = "high"
    excludeFilter file("${project.rootDir}/quality/findbugs/findbugs-filter.xml")
    classes = fileTree('build/intermediates/classes/')

    source 'src'
    include '**/*.java'
    exclude '**/gen/**'

    reports {
        xml.enabled = false
        html.enabled = true
        xml {
            destination "$project.buildDir/reports/findbugs/findbugs.xml"
        }
        html {
            destination "$project.buildDir/reports/findbugs/findbugs.html"
        }
    }

    classpath = files()
}

task pmd(type: Pmd) {
    ignoreFailures = false
    ruleSetFiles = files("${project.rootDir}/quality/pmd/pmd-ruleset.xml")
    ruleSets = []

    source 'src'
    include '**/*.java'
    exclude '**/gen/**'

    reports {
        xml.enabled = false
        html.enabled = true
        xml {
            destination "$project.buildDir/reports/pmd/pmd.xml"
        }
        html {
            destination "$project.buildDir/reports/pmd/pmd.html"
        }
    }
}

check.doLast {
    project.tasks.getByName("checkstyle").execute()
    project.tasks.getByName("findbugs").execute()
    project.tasks.getByName("pmd").execute()
    project.tasks.getByName("lint").execute()
}

checkstyle {
    toolVersion '6.17'    // set Checkstyle version here
}

当我使用 Gradle 5.1.1 版和 Gradle 类路径 3.4.0 版时会发生这种情况。之前我使用的是 Gradle 4.10.1 和类路径版本 3.3.2。

【问题讨论】:

    标签: android gradle android-gradle-plugin


    【解决方案1】:

    在 Gradle 5.x 中,setDestination(Object file) 已被删除 你必须使用

    setDestination(File file)
    

    接受一个文件参数 所以而不是

    destination "$yourpath"

    替换为

    destination file("$yourpath")
    

    检查gradle doc

    【讨论】:

    • 嗨,@tamtom 我做了更改,它工作正常。但是它抛出另一个错误在 quality.gradle() 的最后一部分中找不到行 project.tasks.getByName("checkstyle").execute() 的方法 execute()
    【解决方案2】:

    正确的例子应该是

     reports{
        html.enabled true
        html.destination(file("$yourpath"))
     }
     classpath = files()
    

    【讨论】:

      猜你喜欢
      • 2021-08-30
      • 1970-01-01
      • 2020-05-03
      • 1970-01-01
      • 2023-02-05
      • 2020-08-31
      • 1970-01-01
      • 1970-01-01
      • 2022-11-27
      相关资源
      最近更新 更多