简体   繁体   中英

Can I get checkstyle to run when I press the Run Android Application button in Android Studio

I have a gradle file that includes checkstyle like so

apply plugin: 'checkstyle'

check.dependsOn 'checkstyle'

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

    reports {
        xml.enabled = true
    }

    classpath = files()
}

In this I have a task called checkstyle where I run the checkstyle plugin to check my code for problems.

I currently have my code in a state that fails the checkstyle tests. When I run gradle build I see that this is true.

However when I just hit the 'play' button in Android Studio to build a debug APK the check is never run and the build is successful. I expect the build to fail if there are any errors such as when I do a gradle build .

How can I make Android Studio run gradle check when I build a debug APK?

To make Android Studio run gradle check :

  1. Open Menu->Run->Edit Configurations
  2. Create Android Application run configuration (or use existing one).
  3. Scroll down and find "Gradle-aware Make".
  4. Add "Gradle-aware Make". Enter task ":<your-app-module-name>:check", eg for me task is :app:check .

In addition, you can try Android Check plugin ( https://github.com/noveogroup/android-check ). It has Checkstyle and PMD configurations from-the-box and automatically adds corresponding source checking to standard check task.

Usage:

buildscript {
    repositories { jcenter() }
    dependencies {
        ...
        classpath 'com.noveogroup.android:check:+'
        ...
    }
}

apply plugin: 'com.noveogroup.android.check'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM