gpt4 book ai didi

android - 每当我构建 Android 应用程序时如何执行 checkstyle

转载 作者:太空狗 更新时间:2023-10-29 15:51:09 25 4
gpt4 key购买 nike

我正在尝试将 checkstyle 与 Android 项目集成 - 我的 build.gradle 在下面。我基本上希望看到警告标识在构建时缺少文档的代码。使用此配置,我看到一个名为 checkstyle 的 gradle 任务,我可以手动执行它,但是当我重建项目时它不会被调用(即使我右键单击该任务并说在重建时执行')

我一定是遗漏了什么,因为其他人似乎遇到了完全相反的问题,并试图阻止它在构建时运行。我究竟做错了什么?

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
}
apply plugin: 'checkstyle'

task checkstyle(type: Checkstyle) {
configFile file("${project.rootDir}/config/checkstyle/checkstyle.xml")
source 'src'
include '**/*.java'
exclude '**/gen/**'

reports {
xml.enabled = true
}

classpath = files()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

最佳答案

看来我已经找到了我自己的问题的答案 - here

首先在根级别创建任务

allprojects {
repositories {
jcenter()
}

task checkstyle(type: Checkstyle) {
showViolations = true
configFile file("../settings/checkstyle.xml")

source 'src/main/java'
include '**/*.java'
exclude '**/gen/**'
exclude '**/R.java'
exclude '**/BuildConfig.java'

// empty classpath
classpath = files()
}
}

然后在模块级别添加依赖项。这些只是附加在项目现有 build.gradle 文件的末尾。

apply plugin: 'checkstyle'

preBuild.dependsOn('checkstyle')
assemble.dependsOn('lint')
check.dependsOn('checkstyle')

关于android - 每当我构建 Android 应用程序时如何执行 checkstyle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38659626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com