Skip to content

Commit c57fb78

Browse files
authored
Merge pull request #759 from SimonMarquis/lint/sarif
Android Lint improvements
2 parents 886158d + d136965 commit c57fb78

File tree

8 files changed

+66
-13
lines changed

8 files changed

+66
-13
lines changed

.github/workflows/Build.yaml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ jobs:
3737
- name: Check spotless
3838
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache
3939

40-
- name: Check lint
41-
run: ./gradlew lintDemoDebug
42-
4340
- name: Build all build type and flavor permutations
4441
run: ./gradlew assemble
4542

@@ -49,12 +46,8 @@ jobs:
4946
name: APKs
5047
path: '**/build/outputs/apk/**/*.apk'
5148

52-
- name: Upload lint reports (HTML)
53-
if: always()
54-
uses: actions/upload-artifact@v3
55-
with:
56-
name: lint-reports
57-
path: '**/build/reports/lint-results-*.html'
49+
- name: Run local tests
50+
run: ./gradlew testDemoDebug testProdDebug
5851

5952
test:
6053
runs-on: ubuntu-latest
@@ -122,6 +115,16 @@ jobs:
122115
name: test-results
123116
path: '**/build/test-results/test*UnitTest/**.xml'
124117

118+
- name: Check lint
119+
run: ./gradlew :app:lintProdRelease :app-nia-catalog:lintRelease :lint:lint
120+
121+
- name: Upload lint reports (HTML)
122+
if: always()
123+
uses: actions/upload-artifact@v3
124+
with:
125+
name: lint-reports
126+
path: '**/build/reports/lint-results-*.html'
127+
125128
androidTest:
126129
needs: build
127130
runs-on: macOS-latest # enables hardware acceleration in the virtual machine

build-logic/convention/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ gradlePlugin {
9292
id = "nowinandroid.android.application.flavors"
9393
implementationClass = "AndroidApplicationFlavorsConventionPlugin"
9494
}
95+
register("androidLint") {
96+
id = "nowinandroid.android.lint"
97+
implementationClass = "AndroidLintConventionPlugin"
98+
}
9599
register("jvmLibrary") {
96100
id = "nowinandroid.jvm.library"
97101
implementationClass = "JvmLibraryConventionPlugin"

build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
2929
with(pluginManager) {
3030
apply("com.android.application")
3131
apply("org.jetbrains.kotlin.android")
32+
apply("nowinandroid.android.lint")
3233
}
3334

3435
extensions.configure<ApplicationExtension> {

build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
3333
with(pluginManager) {
3434
apply("com.android.library")
3535
apply("org.jetbrains.kotlin.android")
36+
apply("nowinandroid.android.lint")
3637
}
3738

3839
extensions.configure<LibraryExtension> {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import com.android.build.api.dsl.ApplicationExtension
18+
import com.android.build.api.dsl.LibraryExtension
19+
import com.android.build.api.dsl.Lint
20+
import org.gradle.api.Plugin
21+
import org.gradle.api.Project
22+
import org.gradle.kotlin.dsl.configure
23+
24+
class AndroidLintConventionPlugin : Plugin<Project> {
25+
override fun apply(target: Project) {
26+
with(target) {
27+
when {
28+
pluginManager.hasPlugin("com.android.application") ->
29+
configure<ApplicationExtension> { lint(Lint::configure) }
30+
31+
pluginManager.hasPlugin("com.android.library") ->
32+
configure<LibraryExtension> { lint(Lint::configure) }
33+
34+
else -> {
35+
pluginManager.apply("com.android.lint")
36+
configure<Lint>(Lint::configure)
37+
}
38+
}
39+
}
40+
}
41+
}
42+
43+
private fun Lint.configure() {
44+
xmlReport = true
45+
checkDependencies = true
46+
}

build-logic/convention/src/main/kotlin/JvmLibraryConventionPlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class JvmLibraryConventionPlugin : Plugin<Project> {
2323
with(target) {
2424
with(pluginManager) {
2525
apply("org.jetbrains.kotlin.jvm")
26+
apply("nowinandroid.android.lint")
2627
}
2728
configureKotlinJvm()
2829
}

core/designsystem/build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ android {
2323
defaultConfig {
2424
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2525
}
26-
lint {
27-
checkDependencies = true
28-
}
2926
namespace = "com.google.samples.apps.nowinandroid.core.designsystem"
3027
}
3128

lint/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1919
plugins {
2020
`java-library`
2121
kotlin("jvm")
22-
id("com.android.lint")
22+
id("nowinandroid.android.lint")
2323
}
2424

2525
java {

0 commit comments

Comments
 (0)