gradle添加checkstyle插件

本文详细介绍了如何在Gradle项目中配置Checkstyle进行代码质量检查,包括使用插件、设定工具版本、配置检查规则及源码路径等关键步骤,确保代码遵循统一规范。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

github:git@github.com:Ryan-Miao/springboot-security-demo.git

https://www.cnblogs.com/woshimrf/p/using-checkstyle.html

https://medium.com/@raveensr/how-to-add-checkstyle-and-findbugs-plugins-in-a-gradle-based-project-51759aa843be

 

 

gradle的checkstyle的sourceSets源码设置:

https://www.jianshu.com/p/3f59d62f9f62

 

记录下自己的checkstyle历程:

checkstyle.gradle

apply plugin: 'java'
apply plugin: 'checkstyle'

checkstyle {
    // The version of the code quality tool to be used.
    // The most recent version of Checkstyle can be found at https://github.com/checkstyle/checkstyle/releases
    toolVersion = "8.8"

    // The source sets to be analyzed as part of the check and build tasks.
    // Use 'sourceSets = []' to remove Checkstyle from the check and build tasks.
    //sourceSets = [project.sourceSets.main, project.sourceSets.test]

    // Whether or not to allow the build to continue if there are warnings.
    ignoreFailures = false

    // Whether or not rule violations are to be displayed on the console.
    showViolations = true

    configProperties.projectDir=project.projectDir
    checkstyleMain.configFile=new File(project.projectDir,'/config/checkstyle/google_checks.xml')

    configFile file("config/checkstyle/google_checks.xml")

    println "---------------------"
    sourceSets {
        main{
            java {
                //srcDir "app/src/main/java"
                srcDir "device_provisioning_sdk/src/main/java"

                sourceSets.all {set ->
                    println "${set.name} 的文件是${set.java.srcDirs}"

                }
            }
        }
    }
}

 

checkstyle通过java命令可以正确检查android工程的java代码,跟android库貌似没有关系,记录:

java -jar checkstyle-8.27-all.jar -c /google_checks.xml MyClass.java

应该可以经过改造放到gradle里的?

https://checkstyle.sourceforge.io/cmdline.html#Run_after_compilation

 

 

这个可以正确配置:

https://www.jianshu.com/p/11e97c5e064d

 

checkstyle task执行让其在android studio窗口显示:

解决:在下面的“warning”改为“error”

gradle官网:

https://docs.gradle.org/current/dsl/org.gradle.api.tasks.SourceSet.html

classpath的理解:

https://www.liaoxuefeng.com/wiki/1252599548343744/1260466914339296

 

gradle官方构建系统概述:

https://docs.gradle.org/current/userguide/userguide_single.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值