You are entirely free to pass in live instances of modules to ObjectGraph.create() and graph.plus(). If you have stateful modules, you should do things like:
ObjectGraph graph =
ObjectGraph.create(new LibraryModule1("foo"), LibraryModule2("bar));
That said, if you instantiate the library modules you describe in your question this way they will still fail at compile-time, as they unless you include each other (or mark complete-false). You can simply have LibModule2 include LibModule1, since you say it has objects which depend on objects provided by the latter.
@Module(library = true)
public class LibModule1 {
private final String mString;
public LibModule1(String string) {
mString = string;
}
//... provide methods
}
@Module(includes = LibraryModule1.class)
public class LibModule2 {
private final String mString;
public LibModule2(String string) {
mString = string;
}
//... provide methods
}
I would recommend against complete=false in the scenario you describe in your question, so you don't end up avoiding graph analysis. You should only use complete=false in the case that you are creating a reusable module that expects graph state it cannot include directly via another module, because it will be combined with a module whose identity is unknown at compile-time.
You should only do what you're doing here if you plan on using LibModule2 in the context of alternatives to LibModule1. In the case above, there is no particular reason to not include LibModule1 from LibModule2.
complete=false modules are excluded from all graph analysis, because they do not assert their completeness. But both of these modules can be complete, if the inclusion is given. But you must pass these modules in as instances, because they have no no-args constructors.
You should only use library=true to indicate that some of the bindings provided are provided for consumption by other dependencies, and not to be obtained via graph.get(Foo.class) as entry points to the graph. Essentially, library=true modules are excluded from orphan binding analysis.