https://kotlinlang.org logo
#gradle
Title
# gradle
j

Jan Skrasek

03/02/2023, 12:17 PM
Is there a difference between api vs implementation when using platform bom?
Copy code
api(platform("com.fasterxml.jackson:jackson-bom:2.9.8"))
// vs
implementation(platform("com.fasterxml.jackson:jackson-bom:2.9.8"))
j

jendrik

03/03/2023, 9:37 AM
Similar as with normal dependencies. If you use "implementation" the version constraints from the platform are NOT visible transitively at compile time. Which might lead to different versions being selected when compiling a project (Compile Classpath) vs running the code (Runtime Classpath). Conceptually, it often does not make sense to hide version constraints (which would mean
api
is the better thing to do). But if, e.g., you add the BOM to each project anyway, it does not make a difference (then you could use
implementation
).
j

Jan Skrasek

03/03/2023, 11:29 AM
If you use "implementation" the version constraints from the platform are NOT visible transitively at compile time.
This is something I dont understand much. I have a library L and the app module A. A depends on L. If I use implementation(bom) in L and don't specify lib versions (neither bom) in A, it still compiles, yet you write that those constraints are not present during the compile time - how the compiler knows how to compile A, if there are no version constraints present? Does it use runtime classpath from the L? Thank you for answers 🙂
j

jendrik

03/03/2023, 7:00 PM
Not sure I get where the confusion is. But it can be a confusing topic. If you don't use any of the dependencies covered by the BOM (Jackson the example) in A, the compiler does not need to see them when compiling A. It only needs to see the classes of L itself to compile. Hence, it also does not need any versions from that BOM (which only covers dependencies the compiler does not see). I tried to illustrate the whole concept of visibility of things when you do modularisations in Java by using different "compile classpaths" in this video:

https://youtu.be/Z5n9VK3sOnI

Maybe that helps.
23 Views