From 4bee4e0cd1b77e3a799250417a43f63aecb13ef9 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Mon, 1 Jul 2019 21:00:55 -0400 Subject: [PATCH] Prepare version 0.1.0 --- CHANGELOG.md | 9 ++++ README.md | 103 ++++++++++++++++++++++++++++++++++++++++++++-- gradle.properties | 2 +- 3 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..514c93de --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +Change Log +========== + +Version 0.1.0 +------------- + +*2019-07-01* + +Initial release. diff --git a/README.md b/README.md index 881f8a38..7022b761 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,114 @@ Dagger Reflect ============== -A reflection-based implementation of the [Dagger][dagger] dependency injection library for fast IDE builds. +A reflection-based implementation of the [Dagger][dagger] dependency injection library for fast +IDE builds and tests. More info soon... +**Current release**: [0.1.0](CHANGELOG.md) + +Snapshots of the next development version are available in [Sonatype's `snapshots` repository][snap]. + + Usage ----- -Details soon... +There are two methods of integrating Dagger Reflect to replace Dagger: + +### Partial Reflection + +This approach still uses an annotation processor to generate implementations of your component +interfaces which then call into the reflection runtime. The annotation processor is fully +incremental and does no validation to ensure minimal overhead. + + * Pros: + * Your code does not have to change when switching between Dagger and Dagger Reflect + (modulo limitations below) + + * Cons: + * The use of an annotation processor still causes a build-time impact + +For an Android build, configure your dependencies: + +```groovy +dependencies { + if (properties.containsKey('android.injected.invoked.from.ide')) { + debugAnnotationProcessor 'com.jakewharton.dagger:dagger-reflect-compiler:0.1.0' + debugApi 'com.jakewharton.dagger:dagger-reflect:0.1.0' // or debugImplementation + } else { + debugAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion" + } + releaseAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion" + api "com.google.dagger:dagger:$daggerVersion" // or implementation +} +``` + +This will enable Dagger Reflect only for debug builds in the IDE. + + +### Full Reflection + +This approach avoids all annotation processor usage enabling the quickest builds at the expense of +having to change your production Dagger code. In order to avoid the need to + + * Pros: + * No annotation processors! + + * Cons: + * Rewrite bridges into generated code to call into runtime library. + * Special care has to be taken for R8/ProGuard (for now). + +```groovy +dependencies { + if (properties.containsKey('android.injected.invoked.from.ide')) { + debugApi 'com.jakewharton.dagger:dagger-reflect:0.1.0' // or debugImplementation + } else { + debugAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion" + debugApi 'com.jakewharton.dagger:dagger-codegen:0.1.0' // or debugImplementation + } + releaseAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion" + releaseApi 'com.jakewharton.dagger:dagger-codegen:0.1.0' // or releaseImplementation + api "com.google.dagger:dagger:$daggerVersion" // or implementation +} +``` + +This will enable Dagger Reflect only for debug builds in the IDE. + +When creating a component, builder, or factory in your code, replace calls into generated code with +calls into the static `Dagger` factory with the associated class literal. + +```diff +-MyComponent component = DaggerMyComponent.create(); ++MyComponent component = Dagger.create(MyComponent.class); +``` +```diff +-MyComponent.Factory factory = DaggerMyComponent.factory(); ++MyComponent.Factory factory = Dagger.factory(MyComponent.Factory.class); +``` +```diff +-MyComponent.Builder builder = DaggerMyComponent.builder(); ++MyComponent.Builder builder = Dagger.builder(MyComponent.Builder.class); +``` + + +Unsupported Features and Limitations +------------------------------------ + +### Abstract Classes + +Because Dagger Reflect is implemented using a [`Proxy`][proxy], only interface components, +factories, and builders are supported. + +### Component Visibility + +In order for a factory or builder which is backed by a `Proxy` to create an instance of the +enclosing component which is also backed by a `Proxy`, the component has to be public. + +### Producers -Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap]. +Pretty sure no one but Google uses this. PRs welcome. diff --git a/gradle.properties b/gradle.properties index 6e1d22cb..10d9fb03 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.jakewharton.dagger -VERSION_NAME=0.1.0-SNAPSHOT +VERSION_NAME=0.1.0 POM_DESCRIPTION=Reflection-based Dagger implementation