Hi, I've just started implementing a plugin in Gr...
# community-support
o
Hi, I've just started implementing a plugin in Gradle, and some things are a little bit unclear. When would I use the
kotlin-dsl
plugin? Can I use it for developing plugins, or is it only intended to be used with convention plugins? It seems to add some nice extensions. When should I add @Input / @Output etc. annotations to Extensions/Tasks? It seems they are not strictly required? Thanks in advance
Found an answer to the first question: https://docs.gradle.org/current/userguide/kotlin_dsl.html#sec:kotlin-dsl_plugin
Copy code
The Kotlin DSL Plugin provides a convenient way to develop Kotlin-based projects that contribute build logic. That includes buildSrc projects, included builds and Gradle plugins.
v
kotlin-dsl
applies
java-gradle-plugin
,
kotlin-dsl.base
, and
kotlin-dsl.precompiled-script-plugins
plugins
kotlin-dsl.base
plugin applies
embedded-kotlin
, adds
gradleKotlinDsl()
to the dependencies of
compileOnly
and
testImplementation
configurations, and configures the Kotlin DSL compiler plugins for example for proper SAM conversion for
Action
and similar, or for being able to assign to properties instead of using
.set(...)
and similar. So even if you do not use precompiled script plugins (which you probably meant when saying "convention plugins") the plugin does some quite useful stuff if you develop your plugin in Kotlin. So I would always apply the
kotlin-dsl
plugin if you develop anything related to build logic in Kotlin. input and output annotations you always need on tasks, there they are required or it will fail. On extensions they ususally do not make sense, as the extensions per-se do not have any input or output. Tasks do, Transforms do, and so on. If you use some part of an extension or an extension as
@Nested
input for a task, then it on the other hand might make sense. But usually those should be dedicated DSL objects and not the extension directly. It is most often a better idea to wire single properties in the extension to properties in the task.
o
Thanks for the great explanation!
In this example in the documentation the Extension has a String field annotated with @Input, which looks weird/wrong https://docs.gradle.org/current/userguide/implementing_gradle_plugins_binary.html#sec:mapping_extension_properties_to_task_properties
v
Hm, indeed. Either I just have something not in mind right now which could well be too, or it is just superfluous on the extension property. I'd tend to the latter though.