Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :-)

Regards, Pavel

like image 662
Pavel Arnošt Avatar asked May 11 '26 11:05

Pavel Arnošt


1 Answers

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:

<plugin>
  <groupId>net.bytebuddy</groupId>
  <artifactId>byte-buddy-maven-plugin</artifactId>
  <executions>
    <execution>
      <goals>
        <goal>transform</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <transformations>
      <transformation>
        <plugin>net.bytebuddy.test.SimplePlugin</plugin>
        <!-- Optionally, specify groupId, artifactId, version of the class -->
      </transformation>
    </transformations>
    <!-- Optionally, add 'initialization' block with EntryPoint class -->
  </configuration>
</plugin>

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

like image 126
Rafael Winterhalter Avatar answered May 13 '26 00:05

Rafael Winterhalter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!