-
Notifications
You must be signed in to change notification settings - Fork 5
Home
bangarharshit edited this page Jan 21, 2018
·
3 revisions
Error Prone check to detect missing AutoDispose scope within defined scoped elements.
Here are sample configurations which pulls in both the ErrorProne and the AutoDispose check.
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
plugins {
// we assume you are already using the Java plugin
id "net.ltgt.apt" version "0.13"
id "net.ltgt.errorprone" version "0.0.13"
}
dependencies {
apt "com.uber.autodispose:autodispose-error-prone-checker:x.y.z" // where x.y.z is the latest version.
errorprone "com.google.errorprone:error_prone_core:2.1.3"
}
tasks.withType(JavaCompile) {
// Only if you want to support custom configuration
// Below is a sample configuration which include Conductor and Activity
options.compilerArgs += ["-XepOpt:AutoDisposeLeakCheck"
+ "=com.bluelinelabs.conductor.Controller,android.app.Activity"]
}
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<compilerId>javac-with-errorprone</compilerId>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<source>1.8</source>
<target>1.8</target>
<showWarnings>true</showWarnings>
<annotationProcessorPaths>
<path>
<groupId>com.uber.autodispose</groupId>
<artifactId>autodispose-error-prone-checker</artifactId>
<version>x.y.z</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>--XepOpt:AutoDisposeLeakCheck=com.bluelinelabs.conductor.Controller,android.app.Activity</arg>
</compilerArgs>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac-errorprone</artifactId>
<version>2.8</version>
</dependency>
<!-- override plexus-compiler-javac-errorprone's dependency on
Error Prone with the latest version -->
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.1.3</version>
</dependency>
</dependencies>
</plugin>
</build>
public static class ComponentWithLifecycle extends Activity {
public void observeOnSomething() {
Observable
.interval(1, TimeUnit.SECONDS)
.subscribe(new Consumer<Long>() {
@Override public void accept(Long interval) throws Exception {
System.out.println(interval);
}
});
}
}
./gradlew build
error: [UseAutoDispose] Always apply an AutoDispose scope before subscribing within defined scoped elements.
.subscribe(new Consumer<Long>() {
^
(see https://github.com/uber/AutoDispose/wiki/Error-Prone-Checker)
By default the checker is applied to standard android components with lifecycle and autodispose interfaces:
- Activity
- Fragment
- Support Fragment
- LifecycleScopeProvider
- ScopeProvider
- LifecycleOwner
It can be configured by Error Prone's Command-Line Flags.
The following flag is supported and takes input in a form of comma separated list:
-XepOpt:AutoDisposeLeakCheck=com.bluelinelabs.conductor.Controller,android.app.Activity
The check is now applied to Controller
and Activity
only.