Maven plugin: common dependency in plugin and project, create dependency class object in plugin from class in project

31 views Asked by At

Good day,

I have the following setup:

  • a maven dependency dep1, it contains an abstract class A
  • another maven dependency dep2, which uses dep1 as dependency, and has a class Dep2Class with constructor Dep2Class(A a)
  • maven plugin mvn-pluginthat uses dep2 as dependency
  • project proj that has dep1 as dependency, uses mvn-plugin as plugin and defines a class B extends A

My objective at this point is that mvn-plugin loads class B from proj and feeds it to Dep2Class.

As you might already expect I am getting ClassCastException because proj is loaded with a different class loader than mvn-plugin. I have tried with URIClassLoader and Guava and got the same issue. Reflections appear to be working but the code becomes a mess because I have several Methods from A to call in mvn-plugin. I wanted to try ClassGraph but as far as I understood it does not work easily with GraalVM and I need to use GraalVM.

It sounds strange to me that few people encountered this issue, so I wanted to ask whether anyone has some explanations they can provide. Is there any change I should do in the design? or is there any way to solve the class loader problem?

Thanks a lot, cheers.

0

There are 0 answers