1. What's the actual, under-the-hood difference be...
# gradle
c
1. What's the actual, under-the-hood difference between
implementation
and
compileOnly
? The only difference I found on Google is that
implementation
is available at runtime, but what does it mean exactly? Without a special plugin, Gradle doesn't shade dependencies anyway, no?
đź‘€ 1
b
I'd also be interested to know how exactly
implementation
is different from
api
a
compileOnly
dependencies are only used to provide symbols at build time and won’t be packaged into built program. This is useful e.g. when you are building a library and you provide RxJava bindings but not all users use RxJava and you don’t want RxJava dependency to be added for those who don’t, in which case you can use
compileOnly
.
implementation
dependencies are not available to the consumer of the library while
api
dependencies are.
h
Yes, for normal compliation, the jar wont contain dependencies, you would need to add a pqckaging plugin so that there happens anything. There are different ways plugins process configurations Like implementation or compileOnly. The fat jar plugin embeds everything into a single jar, whereas the application plugin creates a dist zip with all the jars.
c
@no Not really, it describes the difference between
implementation
and
api
and not
compileOnly
.
a
compileOnly
: put the dependency only on the compile classpath
implementation
 : put the dependency on compile and runtime classpath
w
the other factor is how they effect your downstreams. if you are writing library A, and B depends on you,
compileOnly
will not put the dep on B's runtime nor compile classpath,
implementation
will put it on B's runtime classpath only, and
api
will put it on B's compile and runtime classpath (like how
compile
dependencies worked)
c
Would the built JAR files be any different? (without any shading or any plugin at all)
h
No, it wont
But the Metadata of the Module will be, so to put it really simple: your classes inside the jar will be the same, but the pom file in it will not