Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refer to main gradle.properties for lint configuration #335

Merged
merged 1 commit into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ android {
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

lintOptions {
checkDependencies true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do exactly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Lint to detect the mainProject, you'd need your :app module to have checkDependencies = true. This basically means that when you do ./gradlew :app:lint, it goes down and runs lint on its dependencies also.

From Tor's message


Only analyze app/leaf modules

If you have divided your project into many smaller modules - a number of libraries and just a couple of app modules, it's much better to (a) turn on checkDependencies mode and (b) only run lint on the app modules, instead of recursively running lint on each module.

To do this, first add this to your app module's build.gradle file:

android {
    ...
    lintOptions {
        ...
        checkDependencies true
        ...
    }
}         

Then instead of running ./gradlew lintDebug, run ./gradlew :app:lintDebug.

Since you've turned on check-dependencies-mode, running lint on the app module will also run it on all the dependent modules the app depends on -- e.g. all the libraries. But this should also make things run a lot faster, since it's a single lint invocation, where lint shares a lot more computation (such as symbol resolution in the SDK and various shared libraries, etc).

This isn't just a good idea from a performance perspective; you'll also get more accurate results. For example, the unused resource analysis will now correctly know whether a resource defined in a library is consumed by the app module; that doesn't happen when you run lint first on the library, and later on just the app, which is what happens when you run ./gradlew lintDebug. As a bonus you'll also get a single HTML report containing all the results from your codebase, instead of having to hunt around the tree for all the various reports and look at each one separately.

For AutoDispose, this is required since mainProject will only refer to the parent project when you have checkDependencies=true. If you run lint individually on a library module, mainProject = project and there's no way to get access to parent project.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I always thought this would be slower for some reason

}
}

dependencies {
Expand Down
3 changes: 2 additions & 1 deletion sample/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
autodispose.typesWithScope=com.uber.autodispose.sample.CustomScope
autodispose.typesWithScope=com.uber.autodispose.sample.CustomScope
autodispose.lenient=false
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class AutoDisposeDetector: Detector(), SourceCodeScanner {

// Add the custom scopes defined in configuration.
val props = Properties()
context.project.propertyFiles.find { it.name == PROPERTY_FILE }?.apply {
context.mainProject.propertyFiles.find { it.name == PROPERTY_FILE }?.apply {
val content = StringReader(context.client.readFile(this).toString())
props.load(content)
props.getProperty(CUSTOM_SCOPE_KEY)?.let { scopeProperty ->
Expand Down