avaje / avaje-inject

Dependency injection via APT (source code generation) ala "Server-Side Dagger DI"
https://avaje.io/inject
Apache License 2.0
243 stars 24 forks source link

Consider supporting GWT and TeaVM #460

Closed philippTheCat closed 11 months ago

philippTheCat commented 11 months ago

GWT and TeaVM have quite a limited reflection ability at runtime. This led me to want to switch from Spring-context to avaje.

While Avaje seems to not use reflection per say at runtime it still uses some classes from the java.reflect namespace that are unavailable.

Here are the errors I receive:

| ERROR[0]
| Class: io/avaje/inject/spi/DBeanMap.java:60
| Method: io.avaje.inject.spi.DBeanMap.addSuppliedBean(Lio/avaje/inject/spi/SuppliedBean;)V
| Text: Method java.lang.reflect.Type.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[1]
| Class: io/avaje/inject/spi/DBeanMap.java:62
| Method: io.avaje.inject.spi.DBeanMap.addSuppliedBean(Lio/avaje/inject/spi/SuppliedBean;)V
| Text: Method java.lang.Class.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[2]
| Class: io/avaje/inject/spi/DBeanMap.java:74
| Method: io.avaje.inject.spi.DBeanMap.register(Ljava/lang/Object;)V
| Text: Method java.lang.reflect.Type.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[3]
| Class: io/avaje/inject/spi/DBeanMap.java:111
| Method: io.avaje.inject.spi.DBeanMap.get(Ljava/lang/reflect/Type;Ljava/lang/String;)Ljava/lang/Object;
| Text: Method java.lang.reflect.Type.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[4]
| Class: io/avaje/inject/spi/DBeanMap.java:131
| Method: io.avaje.inject.spi.DBeanMap.all(Ljava/lang/reflect/Type;)Ljava/util/List;
| Text: Method java.lang.reflect.Type.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[5]
| Class: io/avaje/inject/spi/DBeanMap.java:158
| Method: io.avaje.inject.spi.DBeanMap.isSupplied(Ljava/lang/String;[Ljava/lang/reflect/Type;)Z
| Text: Method java.lang.reflect.Type.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[6]
| Class: io/avaje/inject/spi/DBeanMap.java:179
| Method: io.avaje.inject.spi.DBeanMap.addSuppliedFor(Ljava/lang/reflect/Type;[Ljava/lang/reflect/Type;Lio/avaje/inject/spi/DContextEntryBean;)V
| Text: Class java.lang.reflect.ParameterizedType was not found
| 
| ----
| 
| ERROR[7]
| Class: io/avaje/inject/spi/DBeanMap.java:180
| Method: io.avaje.inject.spi.DBeanMap.addSuppliedFor(Ljava/lang/reflect/Type;[Ljava/lang/reflect/Type;Lio/avaje/inject/spi/DContextEntryBean;)V
| Text: Method java.lang.reflect.Type.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[8]
| Class: org/apache/commons/lang3/builder/ToStringStyle.java:220
| Method: org.apache.commons.lang3.builder.ToStringStyle.register(Ljava/lang/Object;)V
| Text: Class java.util.WeakHashMap was not found
| 
| ----
| 
| ERROR[9]
| Class: io/avaje/inject/spi/GenericTypeUtil.java:25
| Method: io.avaje.inject.spi.GenericTypeUtil.typeArgument(Ljava/lang/Class;)Ljava/lang/reflect/Type;
| Text: Class java.lang.reflect.ParameterizedType was not found
| 
| ----
| 
| ERROR[10]
| Class: io/avaje/inject/spi/GenericTypeUtil.java:37
| Method: io.avaje.inject.spi.GenericTypeUtil.typeArgument(Ljava/lang/Class;)Ljava/lang/reflect/Type;
| Text: Method java.lang.Class.getTypeParameters()[Ljava/lang/reflect/TypeVariable; was not found
| 
| ----
| 
| ERROR[11]
| Class: io/avaje/inject/spi/GenericTypeUtil.java:40
| Method: io.avaje.inject.spi.GenericTypeUtil.typeArgument(Ljava/lang/Class;)Ljava/lang/reflect/Type;
| Text: Class java.lang.reflect.ParameterizedType was not found
| 
| ----
| 
| ERROR[12]
| Class: io/avaje/inject/spi/GenericTypeUtil.java:41
| Method: io.avaje.inject.spi.GenericTypeUtil.typeArgument(Ljava/lang/Class;)Ljava/lang/reflect/Type;
| Text: Class java.lang.reflect.ParameterizedType was not found
| 
| ----
| 
| ERROR[13]
| Class: io/avaje/inject/spi/GenericTypeUtil.java:45
| Method: io.avaje.inject.spi.GenericTypeUtil.typeArgument(Ljava/lang/Class;)Ljava/lang/reflect/Type;
| Text: Class java.lang.reflect.ParameterizedType was not found
| 
| ----
| 
| ERROR[14]
| Class: io/avaje/inject/spi/GenericTypeUtil.java:48
| Method: io.avaje.inject.spi.GenericTypeUtil.typeArgument(Ljava/lang/Class;)Ljava/lang/reflect/Type;
| Text: Class java.lang.reflect.TypeVariable was not found
| 
| ----
| 
| ERROR[15]
| Class: io/avaje/inject/spi/GenericTypeUtil.java:21
| Method: io.avaje.inject.spi.GenericTypeUtil.typeArgument(Ljava/lang/Class;)Ljava/lang/reflect/Type;
| Text: Method java.lang.Class.getGenericSuperclass()Ljava/lang/reflect/Type; was not found
| 
| ----
| 
| ERROR[16]
| Class: io/avaje/inject/spi/GenericTypeUtil.java:26
| Method: io.avaje.inject.spi.GenericTypeUtil.typeArgument(Ljava/lang/Class;)Ljava/lang/reflect/Type;
| Text: Class java.lang.reflect.ParameterizedType was not found
| 
| ----
| 
| ERROR[17]
| Class: io/avaje/inject/spi/EnrichBean.java:27
| Method: io.avaje.inject.spi.EnrichBean.enrich(Ljava/lang/Object;)Ljava/lang/Object;
| Text: Class org.mockito.Mockito was not found
| 
| ----
=== Removed one error on my side ===
| ----
| 
| ERROR[19]
| Class: io/avaje/inject/DBeanScopeBuilder.java:290
| Method: io.avaje.inject.DBeanScopeBuilder$FactoryOrder.add(Lio/avaje/inject/spi/Module;)V
| Text: Method java.lang.Class.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[20]
| Class: io/avaje/inject/DBeanScopeBuilder.java:311
| Method: io.avaje.inject.DBeanScopeBuilder$FactoryOrder.addFactoryProvides(Lio/avaje/inject/DBeanScopeBuilder$FactoryState;[Ljava/lang/Class;)V
| Text: Method java.lang.Class.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[21]
| Class: io/avaje/inject/DBeanScopeBuilder.java:378
| Method: io.avaje.inject.DBeanScopeBuilder$FactoryOrder.unsatisfiedRequires(Ljava/lang/StringBuilder;[Ljava/lang/Class;Ljava/lang/String;)V
| Text: Method java.lang.Class.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[22]
| Class: io/avaje/inject/DBeanScopeBuilder.java:379
| Method: io.avaje.inject.DBeanScopeBuilder$FactoryOrder.unsatisfiedRequires(Ljava/lang/StringBuilder;[Ljava/lang/Class;Ljava/lang/String;)V
| Text: Method java.lang.Class.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[23]
| Class: io/avaje/inject/DBeanScopeBuilder.java:425
| Method: io.avaje.inject.DBeanScopeBuilder$FactoryOrder.satisfiedDependencies([Ljava/lang/Class;)Z
| Text: Method java.lang.Class.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[24]
| Class: io/avaje/inject/DBeanScopeBuilder.java:198
| Method: io.avaje.inject.DBeanScopeBuilder.initPropertyPlugin()V
| Text: Method java.util.ServiceLoader.findFirst()Ljava/util/Optional; was not found
| 
| ----
| 
| ERROR[25]
| Class: io/avaje/inject/DBeanScopeBuilder.java:239
| Method: io.avaje.inject.DBeanScopeBuilder.build()Lio/avaje/inject/BeanScope;
| Text: Field java.lang.System$Logger$Level.DEBUG was not found
| 
| ----
| 
| ERROR[26]
| Class: io/avaje/inject/spi/DBuilder.java:90
| Method: io.avaje.inject.spi.DBuilder.isAnnotationType(Ljava/lang/reflect/Type;)Z
| Text: Method java.lang.Class.isAnnotation()Z was not found
| 
| ----
| 
| ERROR[27]
| Class: io/avaje/inject/spi/DBuilder.java:384
| Method: io.avaje.inject.spi.DBuilder.errorInjectingNull(Ljava/lang/reflect/Type;Ljava/lang/String;)Ljava/lang/String;
| Text: Method java.lang.reflect.Type.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[28]
| Class: io/avaje/inject/DBeanScopeBuilder.java:482
| Method: io.avaje.inject.DBeanScopeBuilder$FactoryState.toString()Ljava/lang/String;
| Text: Method java.lang.Class.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[29]
| Class: io/avaje/inject/spi/KeyUtil.java:15
| Method: io.avaje.inject.spi.KeyUtil.key(Ljava/lang/reflect/Type;Ljava/lang/String;)Ljava/lang/String;
| Text: Method java.lang.reflect.Type.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[30]
| Class: io/avaje/inject/spi/KeyUtil.java:15
| Method: io.avaje.inject.spi.KeyUtil.key(Ljava/lang/reflect/Type;Ljava/lang/String;)Ljava/lang/String;
| Text: Method java.lang.reflect.Type.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[31]
| Class: io/avaje/applog/AppLog.java:81
| Method: io.avaje.applog.AppLog.<clinit>()V
| Text: Method java.util.ServiceLoader.findFirst()Ljava/util/Optional; was not found
| 
| ----
| 
| ERROR[32]
| Class: io/avaje/inject/spi/GenericType.java:32
| Method: io.avaje.inject.spi.GenericType.getTypeName()Ljava/lang/String;
| Text: Method java.lang.reflect.Type.getTypeName()Ljava/lang/String; was not found
| 
| ----
| 
| ERROR[33]
| Class: io/avaje/inject/spi/DBeanScope.java:26
| Method: io.avaje.inject.spi.DBeanScope.<init>(ZLjava/util/List;Ljava/util/List;Ljava/util/List;Lio/avaje/inject/spi/DBeanMap;Lio/avaje/inject/BeanScope;)V
| Text: Class java.util.concurrent.locks.ReentrantLock was not found
| 
| ----
| 
| ERROR[34]
| Class: io/avaje/inject/spi/DBeanScope.java:50
| Method: io.avaje.inject.spi.DBeanScope.<init>(ZLjava/util/List;Ljava/util/List;Ljava/util/List;Lio/avaje/inject/spi/DBeanMap;Lio/avaje/inject/BeanScope;)V
| Text: Method java.lang.Runtime.addShutdownHook(Ljava/lang/Thread;)V was not found
| 
| ----
| 
| ERROR[35]
| Class: io/avaje/inject/spi/DBeanScope.java:233
| Method: io.avaje.inject.spi.DBeanScope.start(J)Lio/avaje/inject/spi/DBeanScope;
| Text: Class java.util.concurrent.locks.ReentrantLock was not found
| 
| ----
| 
| ERROR[36]
| Class: io/avaje/inject/spi/DBeanScope.java:243
| Method: io.avaje.inject.spi.DBeanScope.start(J)Lio/avaje/inject/spi/DBeanScope;
| Text: Class java.util.concurrent.locks.ReentrantLock was not found
| 
| ----
| 
| ERROR[37]
| Class: io/avaje/inject/spi/DBeanScope.java:245
| Method: io.avaje.inject.spi.DBeanScope.start(J)Lio/avaje/inject/spi/DBeanScope;
| Text: Field java.lang.System$Logger$Level.INFO was not found
| 
| ----
| 
| ERROR[38]
| Class: io/avaje/inject/spi/DBeanScope.java:235
| Method: io.avaje.inject.spi.DBeanScope.start(J)Lio/avaje/inject/spi/DBeanScope;
| Text: Field java.lang.System$Logger$Level.TRACE was not found
| 
| ----
| 
| ERROR[39]
| Class: io/avaje/inject/spi/DBeanScope.java:243
| Method: io.avaje.inject.spi.DBeanScope.start(J)Lio/avaje/inject/spi/DBeanScope;
| Text: Class java.util.concurrent.locks.ReentrantLock was not found
| 
| ----
| 
| ERROR[40]
| Class: io/avaje/inject/spi/DBeanScope.java:251
| Method: io.avaje.inject.spi.DBeanScope.close()V
| Text: Class java.util.concurrent.locks.ReentrantLock was not found
| 
| ----
| 
| ERROR[41]
| Class: io/avaje/inject/spi/DBeanScope.java:254
| Method: io.avaje.inject.spi.DBeanScope.close()V
| Text: Method java.lang.Runtime.removeShutdownHook(Ljava/lang/Thread;)Z was not found
| 
| ----
| 
| ERROR[42]
| Class: io/avaje/inject/spi/DBeanScope.java:269
| Method: io.avaje.inject.spi.DBeanScope.close()V
| Text: Class java.util.concurrent.locks.ReentrantLock was not found
| 
| ----
| 
| ERROR[43]
| Class: io/avaje/inject/spi/DBeanScope.java:259
| Method: io.avaje.inject.spi.DBeanScope.close()V
| Text: Field java.lang.System$Logger$Level.TRACE was not found
| 
| ----
| 
| ERROR[44]
| Class: io/avaje/inject/spi/DBeanScope.java:264
| Method: io.avaje.inject.spi.DBeanScope.close()V
| Text: Field java.lang.System$Logger$Level.ERROR was not found
| 
| ----
| 
| ERROR[45]
| Class: io/avaje/inject/spi/DBeanScope.java:269
| Method: io.avaje.inject.spi.DBeanScope.close()V
| Text: Class java.util.concurrent.locks.ReentrantLock was not found
| 
| ----
| 
| ERROR[46]
| Class: io/avaje/inject/spi/DBeanScope.java:274
| Method: io.avaje.inject.spi.DBeanScope.shutdown()V
| Text: Class java.util.concurrent.locks.ReentrantLock was not found
| 
| ----
| 
| ERROR[47]
| Class: io/avaje/inject/spi/DBeanScope.java:279
| Method: io.avaje.inject.spi.DBeanScope.shutdown()V
| Text: Class java.util.concurrent.locks.ReentrantLock was not found
| 
| ----
| 
| ERROR[48]
| Class: io/avaje/inject/spi/DBeanScope.java:279
| Method: io.avaje.inject.spi.DBeanScope.shutdown()V
| Text: Class java.util.concurrent.locks.ReentrantLock was not found
rbygrave commented 11 months ago

Some of this looks fixable (Change map keys from String to Type or Class). Some of this is JDK 11+ (ReentrantLock, System.Logger).

So we could get closer but then it looks like some things would need to be removed? maintain a fork? Other option?

It could be that you might be interested in using Dagger2 instead? That would mean no lifecycle support & no component testing support but might be closer to what this app needs?

philippTheCat commented 11 months ago

Other option

a pattern I see quite often in the GDX world is that there is usually a central library, and then additional libraries that are backend specific (see here for example: https://github.com/xpenatan/gdx-imgui). Many Libraries also have ios/android specific backends, but these are usually for native libraries and I expect you wouldnt need these

I am aware of dagger2, but I was hoping to use avaje specifically for the lifecycle support, but I think I dont really need it actually So I am gonna give that a go.

SentryMan commented 11 months ago

Tried to give it a go, but too much stuff is missing from these runtimes to get this to work without a significant rewrite of the core API.