Pavel Arnošt Pavel Arnošt - 5 months ago 42
Java Question

Maven plugin instead of javaagent for Byte Buddy?

can there be a maven plugin instead of javaagent to reduce startup time of an application? Many ORM tools have both javaagent and maven plugin, so it should be possible - is it? Or at least something like "CompiledClassFilesBuilder" similar in functionality to AgentBuilder :-)



It is perfectly possible to use Byte Buddy from within a Maven plugin. You can implement a ClassFileLocator for the Maven target after the compile phase and redefine the classes within this folder using a ByteBuddy instance. The API is identical to that of the AgentBuilder inside a transformer.

You would need to implement such a plugin, though. There is none currently existing.

Do however note that this static transformation has its limitations. Using a plugin, it is not possible to redefine bootstrap classes of the VM. It would also be difficult to change library classes as they are external artifacts. Finally, Byte Buddy can register live callbacks that need to be set wt runtime.

UPDATE: I just added the plugin in question and will release a Maven Byte Buddy plugin in version 1.4.21. A transformation can be added as follows:

        <!-- Optionally, specify groupId, artifactId, version of the class -->
    <!-- Optionally, add 'initialization' block with EntryPoint class -->

The two relevant interfaces Plugin and EntryPoint are added to the library directly and are straight-forward to implement.