How to instrument a Java class with ByteBuddy at build time?

762 views
Skip to first unread message

Paolo Di Tommaso

unread,
Feb 3, 2020, 2:01:50 AM2/3/20
to Byte Buddy
The ByteBuddy docs mention that it allows manipulating Java bytecode build time, however, I was unable to find any description regarding that. 

Is that any example showing how ByteBuddy could be injected in a Gradle build? 


Thanks,
Paolo

Rafael Winterhalter

unread,
Feb 3, 2020, 6:17:24 PM2/3/20
to Paolo Di Tommaso, Byte Buddy
Hi Paolo,
Cheers, Rafael

--
You received this message because you are subscribed to the Google Groups "Byte Buddy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to byte-buddy+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/byte-buddy/c3f3f1a1-6d16-44c5-b2db-63e768fa723e%40googlegroups.com.

Paolo Di Tommaso

unread,
Feb 4, 2020, 1:09:45 AM2/4/20
to Rafael Winterhalter, Byte Buddy
Awesome! didn't realise about that, I had only checked the (nice) docs in the ByteBuddy web site. 

Thanks!
p

Paolo Di Tommaso

unread,
Feb 4, 2020, 2:10:55 PM2/4/20
to Byte Buddy
I've managed to setup a minal build using the Bytebuddy gradle plugin.


However, I've realised that instrumentation is applied only to project class files. Instead, my goal is to modify a library class (actually groovy runtime).  

Is there any way to achieve that or I'm on the wrong path? 


Thanks,
Paolo

Rafael Winterhalter

unread,
Feb 5, 2020, 7:16:46 AM2/5/20
to Paolo Di Tommaso, Byte Buddy
Then you would need to directly use the Plugin.Engine.Default in the build package and transform the library's jar file. The location of this file is very build-dependent, therefore the plugin does not have a way for it. Alternatively, you can instrument the library at runtime using a Java agent.

--
You received this message because you are subscribed to the Google Groups "Byte Buddy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to byte-buddy+...@googlegroups.com.

Paolo Di Tommaso

unread,
Feb 5, 2020, 10:26:25 AM2/5/20
to Rafael Winterhalter, Byte Buddy
Likely a bit overkill on my side, thanks for the tips anyhow. 


Cheers,
Paolo

Reply all
Reply to author
Forward
0 new messages