|
// Gradle Tasks for code static code analysis on android apps. |
|
// |
|
// Credits to : https://github.com/artem-zinnatullin/qualitymatters |
|
// |
|
// Usage : |
|
// * Download all files on this GIST. |
|
// * Put the XML files on your root directory under 'code_quality_tools/' folder. |
|
// * Put the this file into your root project directory. |
|
// * On each module you want to check add to the build.gradle the next line : |
|
// apply from: '../code_quality_tools.gradle' |
|
// * Run "gradlew check" |
|
// * Fix your code :) |
|
|
|
ext.preDexLibs = !project.hasProperty('disablePreDex') |
|
|
|
project.plugins.whenPluginAdded { plugin -> |
|
if ('com.android.build.gradle.AppPlugin'.equals(plugin.class.name) || 'com.android.build.gradle.LibraryPlugin'.equals(plugin.class.name)) { |
|
// enable or disable pre-dexing |
|
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs |
|
} |
|
} |
|
|
|
plugins.apply('pmd') |
|
|
|
pmd { |
|
toolVersion = '5.4.0' |
|
} |
|
|
|
task pmd(type: Pmd) { |
|
ignoreFailures = false // Fail early. |
|
ruleSetFiles = project.files(rootProject.file("code_quality_tools/pmd.xml")) |
|
ruleSets = [] |
|
|
|
source = fileTree('src/main/java') |
|
} |
|
|
|
plugins.apply('findbugs') |
|
|
|
task findbugs(type: FindBugs) { |
|
ignoreFailures = false // Fail early. |
|
effort = 'max' |
|
reportLevel = 'low' // Report even low priority problems. |
|
|
|
classes = files("${project.projectDir}/build/intermediates/classes") |
|
source = fileTree('src/main/java') |
|
|
|
// If somebody has an idea how to make this work with support libraries -> open a PR please. |
|
classpath = files() |
|
|
|
excludeFilter = rootProject.file('code_quality_tools/findbugs-filter.xml') |
|
} |
|
|
|
plugins.apply('checkstyle') |
|
|
|
task checkstyle(type: Checkstyle) { |
|
configFile rootProject.file('code_quality_tools/checkstyle.xml') |
|
|
|
ignoreFailures false // Fail early. |
|
showViolations true |
|
|
|
source 'src' |
|
include '**/*.java' |
|
|
|
classpath = files() |
|
} |
|
|
|
afterEvaluate { |
|
tasks.findByName('pmd').dependsOn('assemble') |
|
tasks.findByName('findbugs').dependsOn('assemble') |
|
|
|
def checkTask = tasks.findByName('check') |
|
|
|
checkTask.dependsOn('pmd') |
|
checkTask.dependsOn('findbugs') |
|
checkTask.dependsOn('checkstyle') |
|
|
|
// Log instrumentation tests results. |
|
// tasks.withType(AndroidTestTask) { task -> |
|
// task.doFirst { |
|
// logging.level = LogLevel.INFO |
|
// } |
|
// task.doLast { |
|
// logging.level = LogLevel.LIFECYCLE |
|
// } |
|
// } |
|
} |