Running gradlew lint on specific file(s)
Asked Answered
C

1

6

I'm trying to create pre-commit hook with code style check and other errors. It's a multi-module project in Android Studio (java and kotlin). I was hoping to use lint, but no luck.

My condition is to check only new and modified files (baseline is in order ofc) as the project is way too big to run checks on every commit on every file.

My sh command looks like this:

git diff --name-only HEAD | xargs -I '{}' ./gradlew lint {}\; 

It translates to:

./gradlew lint /path/to/the/file.java

But it always fails on trying to find task called "the path to the file".

When I try to use lint from Android SDK it just prints main: Error: "main" is a Gradle project. To correctly analyze Gradle projects, you should run "gradlew :lint" instead.

Any advice?

Clatter answered 3/8, 2018 at 8:28 Comment(1)
As far as I know, you cannot pass arguments to the Android Lint tool (except android.lintOptions). Also I don't think that running lint over specific files is a good idea: often we declare XML resources and later use them from Java/Kotlin code - this way you lose some important lint features (like unused resources), which require to analyze multiple scopes and files.Bratton
F
0

Edited.

You can use Library/Android/sdk/tools/bin/lint for specific files, but it's not working for gradle projects.

You can create warning baseline like this. https://developer.android.com/studio/write/lint#snapshot

Faught answered 5/9, 2022 at 3:42 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Extremely
Note that developer docs say that this is not supported for gradle projects: developer.android.com/studio/write/lint#standalone-lintCeremonial

© 2022 - 2024 — McMap. All rights reserved.