After spending some time tracking down some dependency issues in GlassFish 3.1, it seems like a little debugging help from HK2
would be very useful.
First, there are situations when injection fails due to a failure at some point in a chain of dependencies. By dependency
I mean that component A depends on component B if A injects a reference to B. Injection fails if for some reason an
implementation of an @Contract interface cannot be found. This is typically because no implementation can be found in the
classpath. The problem becomes more acute if there is a chain of such dependencies spanning multiple modules in a complex
system like GlassFish: A dependsOn B dependOn C dependsOn D. If no implementation of D can be found, then injection of
B and C will also fail. Typically this leaves code in A with a NullPointerException, and no idea why it was not injected.
I have two suggestions for possible assistance with this sort of problem in HK2:
1. Have an option that provides more information about failures to resolve dependencies. Seeing a path for the resolution
failure would be nice, but something a simple as a log message whenever a dependency cannot be resolved would be very
2. Have an option that provides information about what jar files/class paths HK2 is using to search for
dependencies. mvn -X helps, but a more directly targeted option would speed debugging these problems.
This is particularly important for the maven surefire tests, because it is not obvious exactly what
is being scanned by HK2 (in GF 3.1, it's pretty obviously the modules directory).