Search code examples
javaspring-bootkotlingradledependency-injection

Extend or replace compiled library enum


I have a web application developed with Kotlin/Spring Boot and an external library which is successfully injected with Gradle. The project itself works fine.

However, I need one more value in an enum class of that library. Obviously, I can't just add it there, because it's already compiled.

What is the best way to do it? Should I use bytecode editor or inject my own changed version of this library?

I tried to write an enum class inside my project with the same pakage structure. It works fine while compiling the project (I can add new value to the enum and use it), but at runtime I catch java.lang.NoSuchFieldError. Also exclusion of the module of the library doesn't help.


Solution

  • Most straight forward way is to fork that library and change enum source code. Then build it and use result.

    Only work if library licence allows it.