【问题标题】:Define Checkstyle Task with android gradle plugin 3.4.0使用 android gradle 插件 3.4.0 定义 Checkstyle 任务
【发布时间】:2019-04-18 08:59:54
【问题描述】:

我用 gradle 5.11 将我的 build.gradle 文件升级到了 android gradle 插件 3.4.0

我的build.gradle

apply plugin: 'com.android.application'
apply plugin: 'checkstyle'

android {
    compileSdkVersion 28
    buildToolsVersion buildVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "myapp"
        minSdkVersion 21
        targetSdkVersion 28
        versionName "5.20.0"
        versionCode 520

    }

    dataBinding {
        enabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {    
    implementation "com.android.support:support-v4:$supportLibVersion"
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}

task checkstyle(type: Checkstyle) {
    source 'src/'
    include '**/*.java'
    exclude '**/gen/**'
    classpath = files()
    reports {
        xml {
            destination "build/outputs/reports/checkstyle-results.xml"
        }
    }
    group = JavaBasePlugin.VERIFICATION_GROUP
    description = 'Performs checkstyle verification on the code.'
}

task checkstyleReport(dependsOn: 'checkstyle', group: JavaBasePlugin.VERIFICATION_GROUP)  {
    if (file("build/outputs/reports/checkstyle-results.xml").exists()) {
        ant.xslt(in: "build/outputs/reports/checkstyle-results.xml",
                style: "./config/checkstyle/checkstyle.xsl",
                out: "build/outputs/reports/checkstyle-results.html"
        )
    }
}

同步时我收到以下错误消息:

FAILURE:构建失败并出现异常。

  • 其中:构建文件“/Users/cs/Development/project/app/build.gradle”

  • 出了什么问题:评估项目 ':app' 时出现问题。

    在报告 xml 类型上找不到参数 [build/outputs/reports/checkstyle-results.xml] 的方法 destination() org.gradle.api.reporting.internal.TaskGeneratedSingleFileReport。

  • 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • 通过https://help.gradle.org获得更多帮助

1 秒内构建失败错误:未找到 Gradle DSL 方法:'destination()' 可能的原因:项目“项目”可能正在使用 一个版本的 Android Gradle 插件,不包含 方法(例如,在 1.1.0 中添加了“testCompile”)。升级插件到 3.4.0版本和同步项目

项目“项目”可能正在使用 不包含该方法的 Gradle。打开 Gradle 包装文件

构建文件可能缺少 Gradle 插件。应用 Gradle 插件

错误指向这一行:

reports {
        xml {
            destination "build/outputs/reports/checkstyle-results.xml"
        }
    }

destination 的语法在 gradle 中是否已更改?

【问题讨论】:

    标签: android android-gradle-plugin android-gradle-3.4.0


    【解决方案1】:

    解决方案

    reports {
            xml {
                destination file("build/outputs/reports/checkstyle-results.xml")
            }
        }
    

    以前采用对象的方法,但现在需要文件类型作为参数 - 因此参数错误。 所以传入一个文件反而解决了这个问题。

    您可以在此处查看预期的参数类型:

    https://docs.gradle.org/current/javadoc/org/gradle/api/reporting/ConfigurableReport.html#setDestination-java.io.File-

    【讨论】:

      猜你喜欢
      • 2018-05-08
      • 1970-01-01
      • 2017-01-01
      • 2014-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-22
      • 1970-01-01
      相关资源
      最近更新 更多