You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's the outline of a "Hello, world!" example using a Greeter that depends on a RecipientFinder; the greeter says hello to the recipient. The example uses the Java Platform Module System (JPMS).
In module lib, package org.example.lib.internal (not exported): Create an @Inject'able RecipientFinder class.
In module lib, package org.example.lib (exported): Create an @Inject'able Greeter class; its @Inject'ed constructor has a RecipientFinder arg.
In module app: Create a GreeterComponent interface, a @Component that provides a Greeter.
Note: dagger-jpms.zip has a working implementation of this example.
Expected Behavior: This example compiles.
Actual Behavior: This example does not compile. The code for DaggerGreeterComponent in the app module will reference types in org.example.lib.internal, which are not visible since module lib does not export that package.
Generating Code
Without Dagger: I would have a no-arg GreetingFactory.create() method or a static Greeting.create() factory method in the lib module; this method would create the RecipientFinder instance and use it to create a Greeter instance.
With Dagger: DaggerGreetingComponent is what wires everything together. However, since that type is in the app module, it cannot access unexported packages in the lib module.
Context
The real-world context for this was a type whose @Inject'ed constructor depended on both "external" types and "internal" types.
The associated @Module would bind all the "internal" types, which existed in packages that were not exported.
The consumer of said module would be responsible for binding the "external" types.
Now granted, there is no easy fix for this issue, but it can make Dagger unusable with the JPMS.
The text was updated successfully, but these errors were encountered:
Repro Steps
Here's the outline of a "Hello, world!" example using a
Greeter
that depends on aRecipientFinder
; the greeter says hello to the recipient. The example uses the Java Platform Module System (JPMS).lib
, packageorg.example.lib.internal
(not exported): Create an@Inject
'ableRecipientFinder
class.lib
, packageorg.example.lib
(exported): Create an@Inject
'ableGreeter
class; its@Inject
'ed constructor has aRecipientFinder
arg.app
: Create aGreeterComponent
interface, a@Component
that provides aGreeter
.Note: dagger-jpms.zip has a working implementation of this example.
Expected Behavior: This example compiles.
Actual Behavior: This example does not compile. The code for
DaggerGreeterComponent
in theapp
module will reference types inorg.example.lib.internal
, which are not visible since modulelib
does not export that package.Generating Code
Without Dagger: I would have a no-arg
GreetingFactory.create()
method or a staticGreeting.create()
factory method in thelib
module; this method would create theRecipientFinder
instance and use it to create aGreeter
instance.With Dagger:
DaggerGreetingComponent
is what wires everything together. However, since that type is in theapp
module, it cannot access unexported packages in thelib
module.Context
The real-world context for this was a type whose
@Inject
'ed constructor depended on both "external" types and "internal" types.@Module
would bind all the "internal" types, which existed in packages that were not exported.Now granted, there is no easy fix for this issue, but it can make Dagger unusable with the JPMS.
The text was updated successfully, but these errors were encountered: