Hi, how can I define a dependency to be only neede...
# gradle
a
Hi, how can I define a dependency to be only needed for my code to build but optional for the user ?
h
compileOnly
v
Poor-mans solution
compileOnly
. But that is better suited for something like annotations that are really not necessary at usage time. An "optional" dependency is better modeled using feature variants. For Maven customers they will then land in scope
optional
. For Gradle consumers they can depend on the feature variant they need and get the proper dependency without the need to declare it manually while not using it themselves.
a
Okay thanks, to explain a bit more, I'm doing a wrapper in Kotlin/JS about a JS library that have multiple optional modules, I guess I should split my library into multiple libraries with a main that imports the required ones, like how they do
h
Yes, for functionality, I would use another module (don't know variants), like
core
and
feature-x
.
compileOnly
should not be used for features.
☝️ 1