This repository has been archived by the owner on Apr 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quality-android.gradle
111 lines (99 loc) · 3.59 KB
/
quality-android.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
apply from: "${buildscript.sourceFile.getParent()}/quality-java.gradle"
// FIXME(https://docs.gradle.org/4.1-rc-2/userguide/plugins.html#sec:build_scripts_only):
// Replace buildscript+apply with just plugins {}.
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'com.chaitanyapramod.gradle:findbugs-android:1.0'
}
}
apply plugin: com.chaitanyapramod.gradle.android.findbugs.FindBugsAndroidPlugin
// Have to create our own tasks because Android's sourceSets:
// https://android.googlesource.com/platform/tools/build/+/master/gradle/src/main/groovy/com/android/build/gradle/internal/api/DefaultAndroidSourceSet.java
// are not compatible with Gradle sourceSets:
// https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/SourceSet.html
// therefore checkstyle/pmd/etc constructors don't see them.
def sourceDirs(variant) {
variant.sourceSets.java.srcDirs.collect { it.path }.flatten()
}
def defineCheckstyle(variant) {
def name = variant.name.capitalize()
task "checkstyle$name", type: Checkstyle, {
// https://docs.gradle.org/current/dsl/org.gradle.api.plugins.quality.Checkstyle.html
source sourceDirs(variant)
classpath = variant.javaCompile.classpath
}
}
def definePMD(variant) {
def name = variant.name.capitalize()
task "pmd$name", type: Pmd, {
// https://docs.gradle.org/current/dsl/org.gradle.api.plugins.quality.Pmd.html
source sourceDirs(variant)
classpath = variant.javaCompile.classpath
}
}
def getVariants() {
def property = 'applicationVariants'
if (project.plugins.hasPlugin('com.android.library')) {
property = 'libraryVariants'
}
project.android[property]
}
getVariants().all { variant ->
defineCheckstyle(variant)
definePMD(variant)
def name = variant.name.capitalize()
task "checkQuality$name", dependsOn: [
"checkstyle$name",
"pmd$name",
"findbugs$name",
"lint$name",
]
}
project.afterEvaluate {
tasks.withType(tasks['lint'].class.getSuperclass().getSuperclass()) {
finalizedBy 'printLint'
}
}
task printLint {
doLast {
def destination = android.lintOptions.xmlOutput.getAbsolutePath()
// The file is not created on successful run.
if (file(destination).exists()) {
// Write JUnit-style lint for CircleCI to pick up.
ant.xslt(
in: destination,
out: "$buildDir/test-results/lint/results.xml",
style: "$configPath/android-lint/junit.xslt",
)
ant.xslt(
in: destination,
out: destination + '.txt',
style: "$configPath/android-lint/text.xslt",
)
System.err.println file(destination + '.txt').text
}
}
}
android {
lintOptions {
// https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.LintOptions.html
// Enable all warnings, even those disabled by default.
checkAllWarnings true
warningsAsErrors true
abortOnError true
textReport false
htmlReport false
xmlReport true
xmlOutput file('build/reports/android-lint.xml')
if (System.getenv('CIRCLE_BRANCH') == 'master' ||
System.getenv('CIRCLE_TAG')) {
// When building release / master on CircleCI, obsolete dependencies
// are often a timing issue. Should not block the release.
ignore 'GradleDependency'
ignore 'NewerVersionAvailable'
}
}
}