1

I upgraded my build.gradle file to android gradle plugin 3.4.0 with gradle 5.11.

My 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"
        )
    }
}

When syncing I get the following error message:

FAILURE: Build failed with an exception.

  • Where: Build file '/Users/cs/Development/project/app/build.gradle'

  • What went wrong: A problem occurred evaluating project ':app'.

    Could not find method destination() for arguments [build/outputs/reports/checkstyle-results.xml] on Report xml of type org.gradle.api.reporting.internal.TaskGeneratedSingleFileReport.

  • 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.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1s ERROR: Gradle DSL method not found: 'destination()' Possible causes: The project 'project' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0). Upgrade plugin to version 3.4.0 and sync project

The project 'project' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file

The build file may be missing a Gradle plugin. Apply Gradle plugin

The error points to this lines:

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

Has the syntax for destination been changed in gradle?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Christopher
  • 9,682
  • 7
  • 47
  • 76

1 Answers1

3

Solution

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

The method used to take an Object, but now requires a File type as a parameter - hence the parameter error. So passing in a file instead solves the problem.

You can see the expected parameter types here:

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

Josh
  • 529
  • 6
  • 21