android - 使用 android gradle 插件 3.4.0 定义 Checkstyle 任务
问题描述
我使用 gradle将我的build.gradle
文件升级到了 android gradle 插件。3.4.0
5.11
我的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”时出现问题。
在 org.gradle.api.reporting.internal.TaskGeneratedSingleFileReport 类型的报告 xml 上找不到参数 [build/outputs/reports/checkstyle-results.xml] 的方法 destination()。
尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。
在https://help.gradle.org获得更多帮助
BUILD FAILED in 1s ERROR: Gradle DSL method not found: 'destination()' 可能的原因:项目 'project' 可能正在使用不包含该方法的 Android Gradle 插件版本(例如添加了“testCompile”在 1.1.0 中)。将插件升级到 3.4.0 版本并同步项目
项目“项目”可能正在使用不包含该方法的 Gradle 版本。打开 Gradle 包装文件
构建文件可能缺少 Gradle 插件。应用 Gradle 插件
错误指向这一行:
reports {
xml {
destination "build/outputs/reports/checkstyle-results.xml"
}
}
destination
gradle 中的语法是否已更改?
解决方案
解决方案
reports {
xml {
destination file("build/outputs/reports/checkstyle-results.xml")
}
}
该方法用于获取对象,但现在需要文件类型作为参数 - 因此参数错误。所以传入一个文件反而解决了这个问题。
您可以在此处查看预期的参数类型:
推荐阅读
- android - 如何比较两个 ViewInteractions 字符串值
- twig - Twig - 如果数组中的数组值之一
- python - 运行 args = parser.parse_args()。错误:系统退出:2
- asp.net - 如何在 Azure 中为 webAPI 和 MVC 网站共享相同的机器密钥
- typescript - 给定判别式,获取判别联合对应成员的属性类型
- apache-kafka - Kafka - 独立服务器 - 如何决定分区?
- laravel - 为什么我在 laravel 8 登录后无法重定向到家?
- r - 代理背后的 RSelenium 仅获得 NA
- laravel - 如何防止在 Laravel 中公开访问文件?
- php - PHP - 有没有办法从 switch case 到 default?