square / dagger Goto Github PK
View Code? Open in Web Editor NEWA fast dependency injector for Android and Java.
Home Page: https://square.github.io/dagger/
License: Apache License 2.0
A fast dependency injector for Android and Java.
Home Page: https://square.github.io/dagger/
License: Apache License 2.0
The unique thing about Dagger (compared to all other dependency injection frameworks) is that it is completely static, i.e., works at compile time and not at runtime by inspecting the object's type.
Therefore, Dagger should be applicable to C++.
However, I'm not familiar with the internals of Dagger, therefore I wanted to ask the creators/owners if they think it is possible, and what would be the challenges. I would love to start a discussion, and if people are excited, then maybe create a branch :)
I've searched around and there isn't a single decent dependency injection framework for C++. (Mocking using googlemock for C++ is great.)
The biggest benefit of using Dagger over manual dependency injection (DI) would be the "Provider" template that would auto-generate all the factories (maintaining factories is the nightmare of manual DI).
Currently the overriding module replaces instead of adds to the set of multibindings. We should make a behavior-breaking-change and combine 'em all.
A module can't override an included module's provider for a particular type if the included module also overrides a third module. For example:
public static class Thing {
}
@Module
public static class Module1 {
}
@Module(overrides= true, includes = Module1.class)
public static class Module2 {
@Provides
public Thing provideThing() {
return new Thing();
}
}
@Module(overrides= true, includes = Module2.class)
public static class Module3 {
@Provides
public Thing provideThing() {
return new Thing();
}
}
This results in "Duplicate bindings for Thing: Module3.provideThing(), Module2.provideThing()." This is because FullGraphProcessor.processCompleteModule detects "clobbering" within the map of override bindings and records it as an error.
It seems like it should be possible to keep track of the hierarchy of the modules, and have the most-overriding module "win".
If source generated by another processor is depended upon by code that dagger processes, dagger's annotation processors will throw uncaught IllegalStateExceptions and fail on the first code generation pass.
For example:
Take this constructor that exists upon entering annotation processing:
@Inject
public SomeHandWrittenClass(final GeneratedClass dependency)
{/* ... */}
Where GeneratedClass and the module that provides it are generated on the first code generation pass. The following stack trace is produced (in an ant build):
[javac] An annotation processor threw an uncaught exception.
[javac] Consult the following stack trace for details.
[javac] java.lang.UnsupportedOperationException: Unexpected TypeKind ERROR for GeneratedClass
[javac] at dagger.internal.codegen.CodeGen$1.defaultAction(CodeGen.java:147)
[javac] at dagger.internal.codegen.CodeGen$1.defaultAction(CodeGen.java:117)
[javac] at javax.lang.model.util.SimpleTypeVisitor6.visitError(SimpleTypeVisitor6.java:146)
[javac] at com.sun.tools.javac.code.Type$ErrorType.accept(Type.java:1201)
[javac] at dagger.internal.codegen.CodeGen.typeToString(CodeGen.java:117)
[javac] at dagger.internal.codegen.CodeGen.typeToString(CodeGen.java:91)
[javac] at dagger.internal.codegen.InjectProcessor.writeInjectAdapter(InjectProcessor.java:185)
[javac] at dagger.internal.codegen.InjectProcessor.process(InjectProcessor.java:60)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:627)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:556)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:701)
[javac] at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:987)
[javac] at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:353)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:279)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:270)
[javac] at com.sun.tools.javac.Main.compile(Main.java:69)
[javac] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[javac] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[javac] at java.lang.reflect.Method.invoke(Method.java:597)
[javac] at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:56)
[javac] at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1134)
[javac] at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:912)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[javac] at java.lang.reflect.Method.invoke(Method.java:597)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
[javac] at com.android.ant.IfElseTask.execute(IfElseTask.java:120)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[javac] at java.lang.reflect.Method.invoke(Method.java:597)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[javac] at java.lang.reflect.Method.invoke(Method.java:597)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[javac] at java.lang.reflect.Method.invoke(Method.java:597)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.Target.execute(Target.java:390)
[javac] at org.apache.tools.ant.Target.performTasks(Target.java:411)
[javac] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
[javac] at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
[javac] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[javac] at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
[javac] at org.apache.tools.ant.Main.runBuild(Main.java:809)
[javac] at org.apache.tools.ant.Main.startAnt(Main.java:217)
[javac] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
[javac] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
I don't know if you guys are already doing this, or have plans to but I'd be really interested in either participating in this, or starting this myself. It would be useful to write a replacement for Roboguice using Dagger instead of Guice.
java.lang.NullPointerException
at dagger.internal.codegen.DotWriter.nodeName(DotWriter.java:120)
at dagger.internal.codegen.DotWriter.edge(DotWriter.java:69)
at dagger.internal.codegen.GraphVisualizer.write(GraphVisualizer.java:56)
at dagger.internal.codegen.FullGraphProcessor.writeDotFile(FullGraphProcessor.java:204)
at dagger.internal.codegen.FullGraphProcessor.process(FullGraphProcessor.java:67)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:627)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:556)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:701)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:987)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
at com.sun.tools.javac.main.Main.compile(Main.java:353)
at com.sun.tools.javac.main.Main.compile(Main.java:279)
at com.sun.tools.javac.main.Main.compile(Main.java:270)
at com.sun.tools.javac.Main.compile(Main.java:87)
public class Test {
private class Thing {
@Inject Thing() {}
}
}
If a module lists an interface (as opposed to a concrete class) as an entry point, then that graph will always fail validation. It is also impossible to invoke plus
on such a graph. This is a problem for any project that expects to be able to invoke objectGraph.get(Heater.class)
and get an ElectricHeater
instance back.
The validation tries to find a binding for each entry point, but with the "members/" prefix. When that is not found, it tries to create a JIT binding. If the entry point is an interface, then the ReflectivePlugin
refuses to create the binding, (see ReflectivePlugin.java:42). If the entry point is not an interface, then a ReflectiveAtInjectBinding
is created, even if the type does not have an injectable constructor. This JIT binding appears to be spurious, because the provider method is always the one invoked when an instance needs to be provided.
In the following minimal test case, the testValidateAbstractClassEntryPoint()
succeeds as it should, but testValidateInterfaceEntryPoint()
throws an IllegalStateException
.
public class DaggerTest {
public static abstract class AbstractClass { }
public static class Extension extends AbstractClass { }
@Module(entryPoints = AbstractClass.class)
public static class AbstractClassModule {
@Provides public AbstractClass provideAbstractClass() {
return new Extension();
}
}
@Test
public void testValidateAbstractClassEntryPoint() {
ObjectGraph objectGraph = ObjectGraph.create(AbstractClassModule.class);
objectGraph.validate();
}
public interface Interface { }
public static class Implementation implements Interface { }
@Module(entryPoints = Interface.class)
public static class InterfaceModule {
@Provides public Interface provideInterface() {
return new Implementation();
}
}
@Test//(expected = IllegalStateException.class)
public void testValidateInterfaceEntryPoint() {
ObjectGraph objectGraph = ObjectGraph.create(InterfaceModule.class);
objectGraph.validate();
}
}
Currently we just let it pass, which makes for different behavior on reflection vs. code gen.
See also #113
@Provides public Thing provideFoo(MyThing myThing) {
return myThing;
}
@Provides @Singleton
public MyThing provideFoo() {
return new MyThing();
}
Hi, I found TODO in comments:
@Override public T get() {
// TODO (cgruber): Fix concurrency risk.
if (onlyInstance == UNINITIALIZED) {
onlyInstance = binding.get();
}
return (T) onlyInstance;
}
Then, I tried to fix this problem by double-checking locking pattern. But codestyle checker not allows me to do this. Why not? Alternatives?
Jesse's talk at QCon talk touched on a really great feature that visualizes the DAG. Maybe it's just me, but I didn't know I was looking for a dot
file nor did I know where the mythical file was saved. After looking through the code I was able to track it down. It would be helpful to showcase this neat feature on the website.
By default, the dot file is saved as:
target/classes/com/yourapp/YourappModule.dot
You can view this file with GraphViz here http://www.graphviz.org/Download..php.
Hi,
I downloaded dagger and wanted to build it with mavan, but it fails both to validate and test.
I also couldn't build the example directory.
[ERROR] Failed to execute goal on project dagger-androidmanifest-plugin: Could n
ot resolve dependencies for project com.squareup:dagger-androidmanifest-plugin:m
aven-plugin:1.0-SNAPSHOT: Could not find artifact com.squareup:dagger-compiler:j
ar:1.0-SNAPSHOT in sonatype-nexus-snapshots (https://oss.sonatype.org/content/re
positories/snapshots) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyReso
lutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :dagger-androidmanifest-plugin
C:\Users\yzibin\workspace\dagger-master>mvn validate
The example directory:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.861s
[INFO] Finished at: Sat Nov 10 15:14:00 EST 2012
[INFO] Final Memory: 5M/73M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.
5:compile (default-compile) on project dagger-example: Execution default-compile
of goal org.apache.maven.plugins:maven-compiler-plugin:2.5:compile failed: Plug
in org.apache.maven.plugins:maven-compiler-plugin:2.5 or one of its dependencies
could not be resolved: Could not find artifact com.squareup:dagger-compiler:jar
:1.0-SNAPSHOT in apache.snapshots (http://repository.apache.org/snapshots) -> [H
elp 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResoluti
onException
C:\Users\yzibin\workspace\dagger-master\example>
Here is all I had on my console:
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-mo
dule-fml/1.0/doxia-module-fml-1.0.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-dec
oration-model/1.0/doxia-decoration-model-1.0.jar (48 KB at 253.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-mo
dule-xdoc/1.0/doxia-module-xdoc-1.0.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-sit
e-renderer/1.0/doxia-site-renderer-1.0.jar (46 KB at 229.4 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-mo
dule-xhtml/1.0/doxia-module-xhtml-1.0.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-cor
e/1.0/doxia-core-1.0.jar (54 KB at 256.8 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/m
aven-plugin-tools-api/2.8/maven-plugin-tools-api-2.8.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-mod
ule-fml/1.0/doxia-module-fml-1.0.jar (19 KB at 148.4 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/net/sf/jtidy/jtidy/r938/jtidy-r
938.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-mod
ule-xdoc/1.0/doxia-module-xdoc-1.0.jar (28 KB at 271.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
n-reporting-impl/2.0.5/maven-reporting-impl-2.0.5.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-mod
ule-apt/1.0/doxia-module-apt-1.0.jar (46 KB at 129.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-d
oxia-tools/1.0.2/maven-doxia-tools-1.0.2.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-mod
ule-xhtml/1.0/doxia-module-xhtml-1.0.jar (22 KB at 122.4 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/commons-logging/commons-logging
/1.0.4/commons-logging-1.0.4.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven
-reporting-impl/2.0.5/maven-reporting-impl-2.0.5.jar (21 KB at 156.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/m
aven-plugin-tools-java/2.8/maven-plugin-tools-java-2.8.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/ma
ven-plugin-tools-api/2.8/maven-plugin-tools-api-2.8.jar (55 KB at 213.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/1.11
/qdox-1.11.jar
Downloaded: http://repo.maven.apache.org/maven2/net/sf/jtidy/jtidy/r938/jtidy-r9
38.jar (245 KB at 1029.8 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/m
aven-plugin-tools-beanshell/2.8/maven-plugin-tools-beanshell-2.8.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-do
xia-tools/1.0.2/maven-doxia-tools-1.0.2.jar (41 KB at 286.6 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/commons-logging/commons-logging/
1.0.4/commons-logging-1.0.4.jar (38 KB at 297.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/bsh/bsh/1.3.0/bsh-1.3.0.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/ma
ven-plugin-tools-java/2.8/maven-plugin-tools-java-2.8.jar (17 KB at 67.6 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/bsh/bsh/1.3.0/bsh-1.3.0.jar (237
KB at 997.8 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/1.11/
qdox-1.11.jar (172 KB at 622.1 KB/sec)
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/ma
ven-plugin-tools-beanshell/2.8/maven-plugin-tools-beanshell-2.8.jar (14 KB at 25
.8 KB/sec)
[WARNING]
Goal prefix is specified as: 'dagger'. Maven currently expects it to be 'dagger-
androidmanifest'.
[INFO] Using 'UTF-8' encoding to read mojo metadata.
[INFO] Applying mojo extractor for language: java
[INFO] Mojo extractor for language: java found 1 mojo descriptors.
[INFO] Applying mojo extractor for language: bsh
[INFO] Mojo extractor for language: bsh found 0 mojo descriptors.
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ dagger-and
roidmanifest-plugin ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\yzibin\workspace\dagger-mast
er\androidmanifest\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5:compile (default-compile) @ dagger-androidm
anifest-plugin ---
[INFO] Compiling 3 source files to C:\Users\yzibin\workspace\dagger-master\andro
idmanifest\target\classes
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Dagger Example 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ dagger-exa
mple ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\yzibin\workspace\dagger-mast
er\example\src\main\resources
[INFO]
[INFO] Compiling 8 source files to C:\Users\yzibin\workspace\dagger-master\examp
le\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Dagger (Parent) ................................... SUCCESS [0.740s]
[INFO] Dagger ............................................ SUCCESS [4.155s]
[INFO] Dagger Compiler ................................... SUCCESS [0.639s]
[INFO] Dagger AndroidManifest.xml Module Generator ....... SUCCESS [7.273s]
[INFO] Dagger Example .................................... SUCCESS [0.947s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.960s
[INFO] Finished at: Sat Nov 10 15:11:27 EST 2012
[INFO] Final Memory: 13M/68M
[INFO] ------------------------------------------------------------------------
C:\Users\yzibin\workspace\dagger-master>mvn validate
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] Dagger (Parent)
[INFO] Dagger
[INFO] Dagger Compiler
[INFO] Dagger AndroidManifest.xml Module Generator
[INFO] Dagger Example
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Dagger (Parent) 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ dagger-parent ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Dagger 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ dagger ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Dagger Compiler 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Dagger AndroidManifest.xml Module Generator 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Dagger (Parent) ................................... SUCCESS [0.703s]
[INFO] Dagger ............................................ SUCCESS [0.037s]
[INFO] Dagger Compiler ................................... SUCCESS [0.070s]
[INFO] Dagger AndroidManifest.xml Module Generator ....... FAILURE [0.296s]
[INFO] Dagger Example .................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.306s
[INFO] Finished at: Sat Nov 10 15:11:33 EST 2012
[INFO] Final Memory: 4M/75M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project dagger-androidmanifest-plugin: Could n
ot resolve dependencies for project com.squareup:dagger-androidmanifest-plugin:m
aven-plugin:1.0-SNAPSHOT: Failure to find com.squareup:dagger-compiler:jar:1.0-S
NAPSHOT in https://oss.sonatype.org/content/repositories/snapshots was cached in
the local repository, resolution will not be reattempted until the update inter
val of sonatype-nexus-snapshots has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyReso
lutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :dagger-androidmanifest-plugin
C:\Users\yzibin\workspace\dagger-master>mvn test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] Dagger (Parent)
[INFO] Dagger
[INFO] Dagger Compiler
[INFO] Dagger AndroidManifest.xml Module Generator
[INFO] Dagger Example
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Dagger (Parent) 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ dagger-parent ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Dagger 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ dagger ---
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ dagger ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\yzibin\workspace\dagger-mast
er\core\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5:compile (default-compile) @ dagger ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ da
gger ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\yzibin\workspace\dagger-mast
er\core\src\test\resources
[INFO]
[INFO] Compiling 10 source files to C:\Users\yzibin\workspace\dagger-master\core
\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ dagger ---
[INFO] Surefire report directory: C:\Users\yzibin\workspace\dagger-master\core\t
arget\surefire-reports
Running dagger.ExtensionTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.112 sec
Running dagger.InjectionOfLazyTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.017 sec
Running dagger.InjectionTest
Tests run: 31, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.113 sec <<< F
AILURE!
Running dagger.InjectStaticsTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.009 sec
Running dagger.internal.KeysTest
Tests run: 18, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.013 sec
Running dagger.LazyInjectionTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.01 sec
Running dagger.MembersInjectorTest
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.037 sec
Running dagger.ModuleIncludesTest
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.029 sec
Running dagger.ProblemDetectorTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.009 sec
Running dagger.SetBindingTest
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.026 sec
Results :
Tests in error:
noConstructorInjectionsForClassesWithTypeParameters(dagger.InjectionTest): dag
ger.InjectionTest and dagger.InjectionTest$1Parameterized disagree on InnerClass
es attribute
Tests run: 89, Failures: 0, Errors: 1, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Dagger (Parent) ................................... SUCCESS [0.703s]
[INFO] Dagger ............................................ FAILURE [3.255s]
[INFO] Dagger Compiler ................................... SKIPPED
[INFO] Dagger AndroidManifest.xml Module Generator ....... SKIPPED
[INFO] Dagger Example .................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.167s
[INFO] Finished at: Sat Nov 10 15:11:48 EST 2012
[INFO] Final Memory: 9M/103M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
10:test (default-test) on project dagger: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\yzibin\workspace\dagger-master\core\target\sure
fire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureExc
eption
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :dagger
C:\Users\yzibin\workspace\dagger-master>
Are there any plans to benchmark or put numbers behind the 'fast' claim? I'm curious how it compares to Guice specifically.
Given this input:
@Provides Class<? extends MyInterface> provideClassImpl() {
return InterfaceImpl.class;
}
Dagger fails like this:
java.lang.UnsupportedOperationException: Uninjectable type ? extends com.sample.app.di.MyInterface
E/AndroidRuntime( 6701): at dagger.internal.Keys.typeToString(Keys.java:169)
E/AndroidRuntime( 6701): at dagger.internal.Keys.typeToString(Keys.java:161)
E/AndroidRuntime( 6701): at dagger.internal.Keys.get(Keys.java:79)
E/AndroidRuntime( 6701): at dagger.internal.Keys.get(Keys.java:111)
We should handle wildcard types!
Hi Jesse,
Thanks for developing this. I'm glad I didn't work on the same thing simultaneously. Would you mind adding a Google Group for this?
I assume this is only usable via Maven as of now? I use Eclipse. I'm not sure how hard it would be to turn it into an Eclipse plugin, but it sure would be helpful.
Jeff
Generated ModuleAdapter currently only has one binding in getBindingsMethod()
The error is in ProvidesProcessor.java:132 in providerMethodsByClass(),
the code should be :
List methods = result.get(type.toString());
if (methods == null) {
methods = new ArrayList();
result.put(type.toString(), methods);
}
instead of:
List methods = result.get(type);
if (methods == null) {
methods = new ArrayList();
result.put(type.toString(), methods);
}
If some class A, which have dependencies, extends class B, and class B have no dependencies and this class is not a platform type. In this case after code generation A$InjectAdapter will request inject adapter for class B, but it no generated, so it will be created by ReflectivePlugin.
I believe that is not expected behavior. I suggest to check class for the presence of dependencies while inject adapter generates.
@JakeWharton found this:
[ERROR] error: Classes declaring @Provides methods must not be private or abstract: com.squareup.tape.sample.SampleApplication.SampleModule
[ERROR] error: Classes declaring @Provides methods must not be private or abstract: com.squareup.tape.sample.SampleApplication.SampleModule
[INFO] 2 errors
This is probably more a usage question than an issue.
I've got something goofy in denominator wrt dagger. Basically a Provider (like route53) is a dagger module. I want to make it easy to implement and inject provider metadata without having to know too many details. For example, our DNSApiManager uses Provider (a dagger module) directly.
@Inject
DNSApiManager(Provider provider, DNSApi api, Closeable closer) {
this.provider = provider;
this.api = api;
this.closer = closer;
}
Provider defines some things like its name and the type of credentials it can accept as abstract methods. I'd prefer this to be an interface actually.
Anyway, these are needed pre-dagger, as that metadata is used to determine what other dagger modules are needed (chicken-egg problem).
ex. the module list for the graph includes the provider module, and conditionally other modules.
if (provider.defaultCredentialSupplier().isPresent()) { modulesForGraph.add(credentials(provider.defaultCredentialSupplier().get()));
I can't put @provides on on Provider as it is an abstract class, so I ask users to do something in their subclass which is smelly.
@Provides
Provider provideThis() {
return this;
}
I'd like to eliminate the provideThis()
and could if @Provides` abstract methods were somehow possible. Another way would be to refactor denominator to unwind this in some way I'm not aware of.
Thoughts?
No idea how to reproduce, but we've seen this stacktrace a few times in the wild:
java.util.NoSuchElementException
java.util.LinkedList:LinkedList.java:690:in `removeFirstImpl'
java.util.LinkedList:LinkedList.java:677:in `removeFirst'
java.util.LinkedList:LinkedList.java:896:in `poll'
dagger.internal.Linker:Linker.java:79:in `linkRequested'
dagger.ObjectGraph:ObjectGraph.java:224:in `inject'
com.squareup.SquareApplication:SquareApplication.java:55:in `inject'
com.squareup.cardcase.broadcasters.NetworkStateChangeBroadcaster:NetworkStateChangeBroadcaster.java:26:in `onReceive'
android.app.ActivityThread:ActivityThread.java:2103:in `handleReceiver'
---- caused: java.lang.RuntimeException: Unable to start receiver com.squareup.cardcase.broadcasters.NetworkStateChangeBroadcaster: java.util.NoSuchElementException:in `----'
android.app.ActivityThread:ActivityThread.java:2144:in `handleReceiver'
android.app.ActivityThread:ActivityThread.java:135:in `access$2400'
android.app.ActivityThread$H:ActivityThread.java:1114:in `handleMessage'
android.os.Handler:Handler.java:99:in `dispatchMessage'
android.os.Looper:Looper.java:150:in `loop'
android.app.ActivityThread:ActivityThread.java:4385:in `main'
java.lang.reflect.Method:Method.java:-2:in `invokeNative'
java.lang.reflect.Method:Method.java:507:in `invoke'
com.android.internal.os.ZygoteInit$MethodAndArgsCaller:ZygoteInit.java:849:in `run'
com.android.internal.os.ZygoteInit:ZygoteInit.java:607:in `main'
dalvik.system.NativeStart:NativeStart.java:-2:in `main'
I have found a few cases in which start up will take longer than necessary due to dagger reflectively analyze the dependencies of a class.
Two of the cases:
Abstract classes - I have a few abstract classes that have no injected fields. I can't annotate the constructors for these classes with @Inject
(dagger won't compile the class if I do) and so I don't know of a way that I can get the annotation process to create an $InjectAdapter
class for the abstract base class. So, instead, at runtime I have to reflectively evaluate the inheritance chain when I try to inject an instance of the impl.
Classes that were not compiled using the annotation processor - A few times I use a framework for FrameworkClass
and want to inject an instance of MyFrameworkClass
(which extends FrameworkClass
). FrameworkClass
was not written with a DI framework in need and thus I know that there is no need to inject into that class. However, the same issue as above applies - the compile time binding for MyFrameworkClass
requests a binding for the supertype.
In general it would be nice if there was a way to opt out classes from needing bindings. For example:
@Module {
entryPoints = {}...
noBindingsNeeded = {FrameworkClass.class}
}
Alternatively we could also annotate the class (but I would prefer the above, since to me this is analagous to requesting static injection and belongs on the Module)
@NoSuperInject
class MyFrameworkClass extends FrameworkClass {
}
When annotating a private field with visibility with @Inject
, the annotation processor still generates code which directly accesses that field and thus can't be compiled. I think the annotation processor should better create an error clearly indicating the issue. On the other hand injecting private field works when using the reflective plug-in, so maybe the processor could also generate code which accesses the field reflectively in such cases.
#42 changes the dagger-androidmanifest-plugin
packaging to be a real maven plugin. With that, I saw the ActivitiesModule.java
file being generated.
However, this newly generated file wasn't picked up by the annotation processors, so it's not really useful yet.
I read in #33 that you use the maven-exec-plugin
internally to get it working and intend to directly use the plugin, as described in the corresponding Readme.md. Can't wait to see what I missed :) .
Another approach could be to parse the AndroidManifest.xml file when running the annotation processors, rather then at build time.
It kind of make sense, because the AndroidManifest.xml file is a config file for the processors.
It's not straightforward though, because the AndroidManifest.xml file is not a resource file. Theoretically, it can't be accessed from the annotation processors. In practice, it can be done through a dirty hack (that's what we do in AA). There may be better ways...
For the last days I have been struggling with these kind of warnings below. I probably did something wrong as I couldn't find any similar question on the internet.
I refactored several times but they don't go away.
Where can I find what 'capture#128 of ?' means or why is there an unchecked cast and what should I do?
The line numbers refer to the attach method in the generated files but I cannot see anything peculiar.
I have at this moment 5 of them but I show here a constructor, field and provider
The GraphVizualizer draws something
digraph G1 {
concentrate = true;
DbAdapter -> Context;
}
so something I do right.
Some hints are appreciated.
DbAdapterModule$ModuleAdapter.java:33: warning: [unchecked] unchecked cast
[warn] found : dagger.internal.Binding<capture#128 of ?>
[warn] required: dagger.internal.Binding<android.content.Context>
[warn] p0 = (dagger.internal.Binding<android.content.Context>) linker.requestBinding("android.content.Context", .db.DbAdapterModule.class);
[warn]
^
OptionLoaderDelegate$InjectAdapter.java:14: warning: [unchecked] unchecked cast
[warn] found : dagger.internal.Binding<capture#106 of ?>
[warn] required: dagger.internal.Binding<android.content.Context>
[warn] c0 = (dagger.internal.Binding<android.content.Context>) linker.reques
tBinding("android.content.Context", .loaders.OptionLoaderDelegate.class);
[warn]
^
OptionLoaderDelegate$InjectAdapter.java:15: warning: [unchecked] unchecked cast
[warn] found : dagger.internal.Binding<capture#836 of ?>
[warn] required: dagger.internal.Binding<db.DbAdapter>
[warn] f0 = (dagger.internal.Binding<db.DbAdapter>) linker.requestBinding("db.DbAdapter", loaders.OptionLoaderDelegate.class);
[warn]
It need to support assisted injections like guice.
Dagger currently fails to create @Inject
bindings for classes with type parameters. We could fix this. We should weight the upsides and the downsides; one big downside is that it'll require a ton of code, possibly even something that parses a type like Converter<Payment>
.
See also Guice Punches Erasure In The Face.
Hi guys,
A bit of context first... this is a long issue, I had rather sent it on a mailing list, but there's none yet.
I just discovered Dagger : http://www.infoq.com/news/2012/10/dagger .
As you may be aware of, I am the creator of http://androidannotations.org. AA started as a framework providing some of the RoboGuice goodness (@ViewById, etc), at compile time, using annotation processing and code generation. It then added more goodness (@click, @background / @UiThread), and we finally went down the road of dependency injection.
The JSR 330 states :
An injector could rely on reflection or code generation. An injector that uses compile-time code generation may not even have its own run time representation.
Until now, I hadn't seen any implementation doing that. That's one of the ideas we had with AA, but we didn't go in that direction yet.
I know that Dagger is quite likely to be successful, because of its intrinsic qualities and also because there's @JakeWharton and Square behind it :) .
Although you are taking a different path, which means different features and advantages / disadvantages, I also realize that some of the things we do are quite common.
Aside from the implementation details, the main difference in AA is that it generates subclasses to override some methods and add specific behavior. We also do field injection that way, but that's just because the subclass is already there, we could have used package trojans.
I'm certainly not going to stop working on AA, but I also realize that maybe we could leverage some of your work. One way could be to steal some architecture ideas / code pieces that are really good. But an even more interesting way could be to see if there's room to build AA behavior on top of Dagger.
Hence the question : is there any room for such a plugin architecture on top of Dagger ? Basically the ability to extend the processor / add another processor, that would generate subclasses.
I took the CoffeeModule example and added a random :
@Inject
String someString;
The FullGraphProcessor reported an error when started from Maven. However, it didn't report any error when started from Eclipse. It actually runs but no error so far.
I'll try to put some breakpoints in it when I have time.
I am trying to implement a provider for the XmlPullParser class, which unfortunately still follows kind of a singleton pattern:
@Provides XmlPullParser provideXmlPullParser() throws XmlPullParserException {
XmlPullParserFactory xppf = XmlPullParserFactory.newInstance();
XmlPullParser pullParser = xppf.newPullParser();
return pullParser;
}
I know that this can be easily solved with a try/catch, but let's say that I want a blowing destruction of my app if the factory cannot provide the parser. Adding the throws produces an Unhandled exception here.
/**
* Returns the fully provisioned instance satisfying the contract for
* {@code Provider<org.xmlpull.v1.XmlPullParser>}.
*/
@Override
public org.xmlpull.v1.XmlPullParser get() {
return module.provideXmlPullParser();
}
The question that arises here is, wouldn't be better to rethrow whatever Exception here?
(note: if you've already talked about this, just never mind...).
I'm trying to use Dagger with ActionBarSherlock 4.2.0.
I'm getting this error:
Caused by: java.lang.IllegalStateException: Errors creating object graph:
No injectable members on com.actionbarsherlock.app.SherlockFragmentActivity. Do you want to add an injectable constructor?
at dagger.internal.RuntimeLinker.reportErrors(RuntimeLinker.java:55)
at dagger.internal.Linker.linkRequested(Linker.java:114)
at dagger.ObjectGraph.getEntryPointBinding(ObjectGraph.java:247)
at dagger.ObjectGraph.inject(ObjectGraph.java:229)
at com.luisdelarosa.MyApplication.inject(MyApplication.java:38)
This worked fine with a regular FragmentActivity. How can I fix this?
Thanks!
In AtInjectBinding
several types of error are reported by throwing an IllegalArgumentException
. This causes theses errors not to show properly up when using the annotation processor in Eclipse. More specifically, these errors are only shown in the Error Log but not in the Markers view or within the concerned source files.
This problem can be addressed by using the Messager
API of the processing environment for reporting errors/warnings. While this already is done in InjectProcessor#error()
, the concerned element (and annotation) is not passed when invoking processingEnv.getMessager().printMessage()
. This again causes these errors to only show up in Eclipse's error log. When invoking one of the overloaded printMessage()
methods which accept the concerned element/annotation/annotation value, any reported problems will correctly show up as warning or error in the problem markers view and also will be marked with a red wavy line at the concerned element in the editor area.
I've had to explain entryPoints several times, and it seems to confuse some people, as they keep thinking entry-points as being not graph entry points (roots) but application entry points.
We can better document it (i have some thoughts) but renaming entryPoints to graphRoots was suggested to me. Thoughts? Agree? Disagree? Alternative?
In the Coffee example, looking at the generated code :
DripCoffeeModule$ModuleAdapter
:
map.put("coffee.Heater", new provideHeaterBinding(module));
and :
private static class provideHeaterBinding
extends Binding<Heater> {
//...
}
Not much of a problem, just thought that even generated code should follow the rules ;-) .
The problem comes from dagger.internal.codegen.ProvidesProcessor.writeModuleAdapter(TypeElement, List<ExecutableElement>)
:
for (ExecutableElement providerMethod : providerMethods) {
if (providerMethod.getAnnotation(OneOf.class) != null) {
String key = GeneratorKeys.getElementKey(providerMethod);
writer.statement("SetBinding.add(map, %s, new %s(module))", JavaWriter.stringLiteral(key),
providerMethod.getSimpleName().toString() + "Binding");
} else {
String key = GeneratorKeys.get(providerMethod);
writer.statement("map.put(%s, new %s(module))", JavaWriter.stringLiteral(key),
providerMethod.getSimpleName().toString() + "Binding");
}
}
and dagger.internal.codegen.ProvidesProcessor.writeBindingClass(JavaWriter, ExecutableElement)
:
String className = providerMethod.getSimpleName() + "Binding";
Just need to capitalize the first letter.
I've started to annotate dagger/core with nullness annotations of the checker framework. See my changes at https://github.com/reprogrammer/dagger/compare/nullness.
While adding the annotations I ran into cases where the type checker wasn't able to prove the null safety of the program. I've marked these places with @SuppressWarnings("nullness")
or assert var != null : "@SuppressWarnings(nullness)";
.
At this point, my goal is not necessarily to add the nullness annotations to the upstream dagger. Instead, I'd like to see if annotating the program will find any real problems in dagger.
I'd like to point you to my changes so that you can verify if any of the places that I've marked with @SuppressWarnings("nullness")
or assert var != null : "@SuppressWarnings(nullness)";
may trigger a run time exception because of the null unsafety of the program.
Seems like for loops at ReflectiveAtInjectBinding#getDependencies
and ReflectiveModuleAdapter#getDependencies
can be replaced with Collections#addAll
method calls. But Iโm not sure about that because of Set
usage. So there are no pull requests yet. Am I right or wrong?
I have a type with an injectable constructor:
public class Foo {
@Inject public Foo() {}
}
And also a provider method for that type:
@Module
public class FooModule {
@Provides Foo provideFoo() {
return new Foo();
}
}
In this case the object returned from the provider method is used for injection, but I think an error should be raised (as is the case when there are several provider methods returning the same type) since it's not obvious which of the both is used for injection.
Hi,
I see that the plugins are for maven. Do you plan supporting sbt too?
This has been tricky for some users!
https://plus.google.com/u/0/104032734670594482848/posts/Tcp4rVDyBwX
When putting the @Inject
annotation to a method parameter a ClassCastException
is thrown in InjectProcessor#getInjectedClasses()
:
java.lang.ClassCastException: com.sun.tools.javac.code.Symbol$MethodSymbol cannot be cast to javax.lang.model.element.TypeElement
at dagger.internal.codegen.InjectProcessor.getInjectedClasses(InjectProcessor.java:76)
at dagger.internal.codegen.InjectProcessor.process(InjectProcessor.java:58)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
That exception hides the error which would be thrown by the compiler due to the annotation being given at an unsupported element type ("annotation type not applicable to this kind of declaration").
While the POM contains a common groupId "com.squareup" and artifactId "dagger", the package name is simply "dagger".
This is highly uncommon and adds risk of package name or dependency clashes you'd avoid, if the package was properly named.
I tried adding dagger to an android eclipse project. dagger-0.9.jar library was added to java build path. Under java compiler annotation processor was enabled, and dagger-compiler-0.9.jar was added as factory path. Consistently get
Internal compiler error: java.lang.NoClassDefFoundError: Could not initialize class dagger.internal.codegen.ProvidesProcessor at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) BuildConfig.java
How about a simple "how-to" on adding dagger support to eclipse - not everyone is using Marven. You guys did a good job explaining how to use the framework but installation instructions suck.
I have tried to reproduce following injections:
https://github.com/emmby/roboguice/blob/master/roboguice/src/main/java/roboguice/util/RoboAsyncTask.java
So there is generic SafeAsyncTask<T>
and i'd like to make injectable child class.
During code generation process I get following error:
[javac] An annotation processor threw an uncaught exception.
[javac] Consult the following stack trace for details.
[javac] java.lang.IllegalArgumentException: Unexpected key: me.lyft.android.tasks.SafeAsyncTask<>
[javac] at dagger.internal.codegen.GraphVisualizer.shortName(GraphVisualizer.java:99)
[javac] at dagger.internal.codegen.GraphVisualizer.buildNamesIndex(GraphVisualizer.java:69)
[javac] at dagger.internal.codegen.GraphVisualizer.write(GraphVisualizer.java:46)
[javac] at dagger.internal.codegen.FullGraphProcessor.writeDotFile(FullGraphProcessor.java:204)
[javac] at dagger.internal.codegen.FullGraphProcessor.process(FullGraphProcessor.java:67)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:627)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:556)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:701)
[javac] at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:987)
[javac] at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:353)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:279)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:270)
[javac] at com.sun.tools.javac.Main.compile(Main.java:69)
[javac] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[javac] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[javac] at java.lang.reflect.Method.invoke(Method.java:597)
[javac] at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:56)
[javac] at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1134)
[javac] at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:912)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[javac] at java.lang.reflect.Method.invoke(Method.java:597)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
[javac] at com.android.ant.IfElseTask.execute(IfElseTask.java:120)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[javac] at java.lang.reflect.Method.invoke(Method.java:597)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[javac] at java.lang.reflect.Method.invoke(Method.java:597)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[javac] at java.lang.reflect.Method.invoke(Method.java:597)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.Target.execute(Target.java:390)
[javac] at org.apache.tools.ant.Target.performTasks(Target.java:411)
[javac] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
[javac] at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
[javac] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[javac] at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
[javac] at org.apache.tools.ant.Main.runBuild(Main.java:809)
[javac] at org.apache.tools.ant.Main.startAnt(Main.java:217)
[javac] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
[javac] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
I am using Dagger on Anrdoid and I am having a TypeNotPresentException when one of my Android component is set to false.
Please find below the detailed of what I am doing:
I have two declared components in my AnrdoidManifest:
below an extract of my AndroidManifest.xml
<activity
android:name=".ui.search.SearchHoneycombActivity"
android:enabled="@bool/hasHoneycomb">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<activity
android:name=".ui.search.SearchEclairActivity"
android:enabled="@bool/priorHoneycomb">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
Here the extract of my only module
@Module(
entryPoints = {
SearchHoneycombActivity.class,
SearchEclairActivity.class,
...}})
public class ProdModule {
...
Apparently declaring the entryPoints are mandatory. I was wondering how to deal with this tricky use case?
We need a project using a maven build to create an android app using dagger so demonstrate getting started with android (and to ensure that a path to clean and easy eclipse useage is available)
First, thanks for this library!
I am learning Dagger and Dependency Injection design pattern in general.
I was wondering how would you solve cross dependency injections with Dagger? Maybe this question show a misunderstanding of the dependency injection design pattern or an architecture design issue in my code.
The code below represent what I am trying to do but obviously crashing in StackOverflow
public class SessionController {
private final SyncController mSyncController;
@Inject
public SessionController(final Context context, SyncController syncController {
mSyncController = syncController;
}
}
public class SyncController {
private final SessionController mSessionController;
@Inject
public SyncController(final Context context, SessionController sessionController {
mSessionController = sessionController;
}
}
public class ProdModule {
private final Context appContext;
public ProdModule(final Context appContext) {
this.appContext = appContext;
}
@Provides
@Singleton
Bus provideBus() {
return new Bus();
}
@Provides
@Singleton
Controller provideSyncController(Bus bus, SessionController sessionController) {
return new SyncController(bus, sessionController);
}
@Provides
@Singleton
SessionController provideSessionController(Controller controller, SyncController syncController) {
return new SessionController(appContext, syncController);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.