It's not really a job for the compiler. You could either:
• rewrite your Source files before compilation (maybe regexes would do)
• rewrite the bytecode after compilation (using something like asm)
• overlay guava with your own guava jar at runtime
Martin
08/18/2023, 12:51 PM
I guess you could write your own compiler plugin that changes the imports during compilation but that sounds not trivial and quite the footgun
Martin
08/18/2023, 12:51 PM
What are you trying to do? If you want to substitute the guava version, I would do so at runtime
l
Lu Cao
08/18/2023, 1:10 PM
Emm……thank you martin!
It’s a little bit complicated… In my project I have some dependencies like hadoop\hive etc.. and those packages contain guava classes(can not be excluded…) and I want to avoid the conflict between our own dependency and those from external libs…
m
Martin
08/18/2023, 1:26 PM
If you control your code, is there a reason you can't use your relocated version of guava in your sources? By compiling against your own guava you'll have more guarantees. If not, it's dangerous because you're compiling against a different version of guava than the runtime one