Search code examples
javagradlewarktor

WAR - Gradle multi-module app - TypeNotPresentException


I have an application with a Gradle module structure similar to this:

  • app - applies war
  • common/utilities
  • common/auth etc.

The app module applies the WAR plugin. When deployed to a remote server, this exception comes back:

Caused by: java.lang.TypeNotPresentException: Type [SomeClass] not present
    at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
    at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
    at sun.reflect.generics.repository.ClassRepository.getSuperclass(ClassRepository.java:90)
    at java.lang.Class.getGenericSuperclass(Class.java:777)
    at org.kodein.di.TypeReference.<init>(types.kt:272)

Clearly, classes from depended-on modules are not being brought into the WAR somehow (which is exposed via Kodein service locator usage) - this is not intuitive since that wouldn't be the case if it was packaged into a JAR or AAR.

Anyone know why this may be happening and how I can change my Gradle configuration to fix it?


Edit: if I expand the WAR, I see external Maven dependencies are brought into lib as JARs along with non-app modules. All of the compiled Kotlin classes from the app module are in classes. I guess it's not working because the main app JAR is not bringing in the module JARs, for some reason.


Solution

  • The problem was simpler than expected. My module structure has modules like this:

    • :app
    • :common:auth:public
    • :common:auth:impl
    • :common:data:public
    • :common:data:impl

    The public and impl submodules go into the WAR as public.jar and impl.jar, it doesn't handle duplicates at all. So some modules were being left out.

    I couldn't figure out how to change the outputted JAR names so I ended up changing the names like this:

    • :app
    • :common:auth:data-public
    • :common:auth:data-impl
    • :common:data:data-public
    • :common:data:data-impl