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

Peter

11/09/2023, 6:50 PM
is
internal
modifier good enough reason, to make a Kotlin module 🤔 I have a bunch of packages, that would benefit from that modifier, but there are not many classes in there.
c

CLOVIS

11/09/2023, 8:25 PM
If those packages fit in a greater unit, yes, definitely. Modules also have the benefit of faster incremental compilation, and they can each define their own dependencies, so you can control the visibility of external dependencies as well.
p

Peter

11/09/2023, 8:31 PM
Should I be worried about flat compile time cost, that is added just by adding an empty module for example?
c

CLOVIS

11/09/2023, 8:33 PM
Short answer: no. Situation 1: you have a single enormous module. • You edit a class. • The entire module is recompiled. Situation 2: you have two modules
:a
and
:b
, with
:b
depending on
:a
. • You edit a class in
:b
. •
:a
hasn't changed, so only
:b
is recompiled. So, apart from the very first build when you clone the project, it's usually faster.
(the real world is a bit more complicated because the Kotlin compiler is able to do incremental compilation in a single module) (also, compilation is not the only thing that happens, and Gradle can execute the other things in parallel (e.g. publish your modules, run tests…))
c

Casey Brooks

11/09/2023, 8:35 PM
Honestly, in my experience the biggest penalty for additional Gradle modules is from the configuration time, not from compilation. But the Gradle Configuration Cache eliminates that to an incredible degree, so there’s really not much of a build performance penalty anymore for adding new modules when using the configuration cache
👍 1
c

CLOVIS

11/09/2023, 8:36 PM
(and if you can't enable the configuration cache, configuration-on-demand is almost as good and less risky)
p

Peter

11/09/2023, 8:40 PM
ok, thank you for explaining guys!