I know how an empty beans.xml
can resolve the issue in case of a straightforward dependency as described here
The question is how we can achieve a similar result when the dependency between the submodules has the opposite direction. So based on the example of the linked question what if instead of this setup
// service-module build.gradle
dependencies {
implementation project(":library-module")
}
we had this one
// library-module build.gradle
dependencies {
implementation project(":service-module")
}
As a use case consider a service that follows the ports & adapters architecture,
where ports are located in the application
module and the adapters implementations are located in the adapters
module.
// application module
public interface WebPort {}
---
@ApplicationScoped
public class AppService {
@Inject
WebPort webPort;
...
}
//adapters module
// build.gradle
dependencies {
// this is in order to have the WebPort available
implementation project(":application")
}
@ApplicationScoped
public class WebAdapter implements WebPort {
...
}
Currently, this setup throws an UnsatisfiedResolutionException
as the application-module cannot see the WebAdapter
bean.
Is it possible to have a similar working setup?
I've figured out what was the issue. Apparently having the quarkus plugin declared in both modules' build.gradle causes confusion. It seems that the following dependency
dependencies {
// this is in order to have the WebPort available
implementation project(":application")
}
instructs gradle to start building the application module first, which makes sense, but in this specific case causes the unsatisfied dependency error since the implementation bean exists in the adapters module which has not been built yet.
Removing the quarkus plugin from the application module seems to fix the issue. Alternatively, there is the option of creating a 3rd module which contains the 2 original module as dependencies and have the quarkus plugin only in this 3rd module, which can be the entry point of the whole application by having the following class, for example:
@QuarkusMain
public class Main {
public static void main(String... args) {
Quarkus.run(args);
}
}
The above setup fixes the issue, but the annoying warning of unsatisfied dependency remains on Intellij. It would be nice if there was a way to make Intellij understand what's going on. Any hint on this is more than welcome.