java 21 - be careful with the order of dependencies

1,752 views
Skip to first unread message

Olivier Bourgain

unread,
Oct 6, 2023, 5:35:15 AM10/6/23
to Byte Buddy
Hello,

I had an issue in a test with bytebuddy failing to mock some third party class.
I tried to make a minimal reproducer project with just the third party lib and mockito, but this time it worked.

I then analyzed the dependencies of the project. I found the assertj is using bytebuddy 1.12.21 (which don't support java 21) and as it was declared before mockito in my pom.xml, and so its version of bytebuddy was picked by Maven as asserj was declared.before Mockito. (due to picking the nearest cf https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#transitive-dependencies ).

Mark Waite

unread,
Oct 14, 2023, 1:30:05 PM10/14/23
to Byte Buddy
Thanks so much for describing this!  We're sweeping through plugins in the Jenkins project to test with Java 21 and we've encountered this on multiple occasions.  I didn't know what to do about it until I saw your message.  Thanks very much!

Mark Waite

Verhás István

unread,
Jan 11, 2025, 12:27:14 PMJan 11
to Byte Buddy
Maybe the order fixed your issue, but it is a fragile solution. Unintentional changes can break your project again. The referred documentation and also my practice show a better way to fix the transitive dependency version issue
>> Dependency management - this allows project authors to directly specify the versions of artifacts to be used when they are encountered in transitive dependencies or in dependencies where no version has been specified. 
Simple declare in the dependency management section the required version of byte buddy. It will not be changed unintentionally. 
Reply all
Reply to author
Forward
0 new messages