-
Notifications
You must be signed in to change notification settings - Fork 0
Overriding dependencies
When you extend modules, you inherit all dependecies from all superclasses, even if one of them is annotated with AbstractModule.
However, you may decide that your subclass modules no longer need certain dependencies, or you may want to change whether they're required.
To override dependencies all you need to do is to use ModuleDependencies annotation once again.
Tip
You can add/override dependencies regardless of whether your module class is annotated with AbstractModule or not.
Let's say ModuleA extends ModuleB, which requires ModuleC, and you want ModuleC not to be a dependency of ModuleA.
In this case, removed field from ModuleDependencies comes to help.
The following example makes ModuleC no longer a dependency of ModuleA, while plain ModuleB still requires ModuleC to function.
import net.hypejet.modules.annotation.ModuleDependencies;
@ModuleDependencies(removed = ModuleC.class)
public final class ModuleA extends ModuleB {
// Your module contents
}But what if you want ModuleC to be optional instead? You just need to replace the removed field with optional.
import net.hypejet.modules.annotation.ModuleDependencies;
@ModuleDependencies(optional = ModuleC.class)
public final class ModuleA extends ModuleB {
// Your module contents
}If ModuleC was an optional dependency of ModuleB instead, and you wanted to make it required to load ModuleA,
you would need to add ModuleC to the array from the required field of the dependency-overriding annotation.
Copyright © 2026 Hypejet
Basic knowledge:
Advanced usage: