Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Android gradle plugin & checkstyle working together / command line usage

Tags:

I'm evaluating the ability of the new gradle-based build system to reproduce our current ant-based build process and, as a gradle beginner, I failed to get checkstyle running with the android gradle plugin.

Environment:

  • gradle 1.6 running fine on a standard java project (checkstyle check target included)

  • up-to-date android SDK (22.0.1 with platform tools and build tools 17)

  • no eclipse, no android studio, only my lovely terminal

Symptom:

The target project is https://github.com/nibua-r/LigoTextDemo and I succeeded to build it using gradle but if I naively add apply plugin: checkstyle to my build.gradle:

buildscript {   repositories {     mavenCentral()   }   dependencies {     classpath 'com.android.tools.build:gradle:0.4.2'   } } apply plugin: 'android' apply plugin: 'checkstyle'  android {   buildToolsVersion '17'   compileSdkVersion 15   testBuildType 'debug'    defaultConfig {     versionCode = 1     versionName = '1.0'     minSdkVersion 12     targetSdkVersion 15   }    buildTypes {     debug {       packageNameSuffix = '.debug'     }   } } 

then gradle check doesn't even complain on not finding the checkstyle.xml file (at the default config/checkstyle location) and returns:

:check UP-TO-DATE  BUILD SUCCESSFUL 

What's needed:

First, I just need a running checkstyle target. Then, I need to automate checkstyle running as a dependency of the compilation (but lets get the chekstyle target up and running first).

Assumption:

This may be related to the fact that (from the [user guide][1]):

The Android plugin […] uses its own sourceSets

but I'm not enough gradle-efficient to understand what I'm missing there. Please, gradle Master, enlighten me with your valuable knowledge!

like image 600
Renaud Avatar asked Jun 11 '13 17:06

Renaud


People also ask

Where is Android Gradle plugin located?

You can specify the Gradle version in either the File > Project Structure > Project menu in Android Studio, or update your Gradle version using the command line.

What is Android Studio Gradle plugin?

The Android Gradle plugin (AGP) is the official build system for Android applications. It includes support for compiling many different types of sources and linking them together into an application that you can run on a physical Android device or an emulator.


2 Answers

I got pmd, findbugs, and checkstyle working with Gradle 1.12 android plugin 0.12.+ using the following script:

apply plugin: 'checkstyle' apply plugin: 'findbugs' apply plugin: 'pmd'  check.dependsOn 'checkstyle', 'findbugs', 'pmd'  task checkstyle(type: Checkstyle) {     configFile file("${project.rootDir}/config/quality/checkstyle/checkstyle.xml")     source 'src'     include '**/*.java'     exclude '**/gen/**'      classpath = files() }  task findbugs(type: FindBugs) {     ignoreFailures = true     effort = "max"     reportLevel = "high"     excludeFilter = new File("${project.rootDir}/config/quality/findbugs/findbugs-filter.xml")     classes = files("$project.buildDir/intermediates/classes/")      source 'src'     include '**/*.java'     exclude '**/gen/**'      reports {         xml {             destination "$project.buildDir/reports/findbugs/findbugs.xml"             xml.withMessages true         }     }      classpath = files() }  task pmd(type: Pmd) {     ruleSetFiles = files("${project.rootDir}/config/quality/pmd/pmd-ruleset.xml")     ignoreFailures = true     ruleSets = ["basic", "braces", "strings"]      source 'src'     include '**/*.java'     exclude '**/gen/**'      reports {         xml.enabled = true         html.enabled = false     } } 

Running gradle build in command line will run all code quality plugins and generate xml reports in app/build/reports/ which are then ready to be viewed or parsed by CI tools.

like image 121
Marco RS Avatar answered Nov 10 '22 05:11

Marco RS


Someone has a great answer to solve integrating PMD, findbugs and checkstyle with Gradle for Android. Unfortunately, the only solution for now is based on ant : http://sethrylan.org/2013/07/14/gradle-android-findbugs.html

I wish gradle will one day allow to do as much as maven for Android.

--- Update as of October 2013

With Gradle 1.8 and Android plugin for Gradle 0.6.+, you don't need this anymore. Android sourcesets and configurations are now compatible with the java plugin and all quality plugin work out of the box.

This includes pmd, findbugs, checkstyle and classycle.

--- Update A configuration, largely inspired from the project mentioned above, is proposed in this open source project as well, plus other tools.

like image 45
Snicolas Avatar answered Nov 10 '22 05:11

Snicolas