Hi all, I was astounded to see that the publicatio...
# kotlin-dsl
t
Hi all, I was astounded to see that the publication of my very small build convention plugin created a JAR file of more than one megabyte of size. After unzipping the JAR and looking into its contents I saw hundreds and hundreds of small auto-generated files underneath
gradle/kotlin/dsl/accessors
, in total more than 900 files totalling about 4,2 MB uncompressed. Because I want to keep my upload / consumption times low I wonder if I could tell Gradle to not generate these accessors for my build convention plugins? Or is there some smart way of telling Gradle to only package those accessors that are actually used?
🤯 1
m
Are you using the
kotlin-dsl
plugin? If yes, might be worth using just
embedded-kotlin
?
v
The point is then to not use precompiled script plugins, but regular Kotlin classes. You can do that also with the
kotlin-dsl
plugin, preserving some of the benefits like sam-with-receiver plugin, property assignment plugn,
kotlinDsl()
dependency, ... But as for those classes no accessors are generated, ...
v
The accessors are for the ones who will use the plugin, so there's no way to tell which "are used" at plugin build time. You could probably decompile the accessors to identify how they are related to the plugin. Note: it would probably be better to generate the accessors at the plugin build time (once) rather than generate the same accessors at the plugin use time (more than once)
v
What are you talking about? The accessors are not for consumers of the plugin. Consumers get their own accessors generated.
t
So, how exactly would I configure a build convention plugin without generated kotlin accessors? I suppose applying the
kotlin-dsl
plugin will trigger the creation of the accessors and this is not configurable with the
kotlin-dsl
plugin (I guess it might even be it's main purpose). So, again, if I don't apply
kotlin-dsl
, do I (just) have to specify
implementation(kotlinDsl())
in my plugin's dependency block?
v
Again, the accessors are generated for precompiled Kotlin DSL script plugins. Handling precompiled script plugins is one of the responsibilities of the
kotlin-dsl
plugin. If you do not want accessors, do not use precompiled script plugins. You can keep using the
kotlin-dsl
plugin to have the other aspects it is doing. The point is to stop using precompiled Kotlin DSL script plugins.
Simply write your convention plugin as normal
.kt
plugins or any other JVM language.
t
Ok, I see, thanks for clearing that up. That then also requires manual plugin registration aso.
v
Yes, you need to register them in
gradlePlugin { plugins { ... } }
unless you find something that provides a different way. I mean to remember that there was some thing to generate it from an annotation, but I don't remember the details.
👍 1
n
You could also run a tree shaker to reduce the size. The shadow plugin has one built in or you can use R8
Probably easier to just not use Kotlin-dsl though ¯\_(ツ)_/¯
2
v
I checked the contents of the accessors, and they have nothing to do with the plugin code. The accessors relate to the the items used by the plugin. We need to file an issue to the Gradle team so they exclude the accessors from the jar