Skip to content

Commit 1397575

Browse files
authored
error when io.avaje.inject.spi.AvajeModule class not found (#916)
If the project does not have the `avaje-inject` dependency configured on the project but the code-generator is configured then it will yield an NPE. This fix will at least raise an exception with an explanation.
1 parent eb8e053 commit 1397575

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

inject-generator/src/main/java/io/avaje/inject/generator/ExternalProvider.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ final class ExternalProvider {
5757
"io.avaje.validation.Validator",
5858
"io.avaje.inject.aop.AspectProvider<io.avaje.validation.ValidMethod>")),
5959
entry("io.avaje.validation.http.HttpValidatorProvider", of("io.avaje.http.api.Validator")));
60+
private static final String CLASS_NAME_AVAJE_MODULE = "io.avaje.inject.spi.AvajeModule";
6061
private static final List<MetaData> externalMeta = new ArrayList<>();
6162

6263
private ExternalProvider() {
@@ -227,7 +228,15 @@ static void scanAllAvajeModules(Collection<String> providedTypes) {
227228
return;
228229
}
229230
final var types = APContext.types();
230-
final var avajeModuleType = APContext.typeElement("io.avaje.inject.spi.AvajeModule").asType();
231+
final var typeElement = APContext.typeElement(CLASS_NAME_AVAJE_MODULE);
232+
233+
if (typeElement == null) {
234+
throw new IllegalStateException(String.format(
235+
"Unable to find the type [%s]; ensure that the `avaje-inject` dependency is included in your project",
236+
CLASS_NAME_AVAJE_MODULE));
237+
}
238+
239+
final var avajeModuleType = typeElement.asType();
231240
injectExtensions()
232241
.filter(t -> t.getInterfaces().stream().anyMatch(i -> types.isAssignable(i, avajeModuleType)))
233242
.distinct()

0 commit comments

Comments
 (0)