Hello! Is out there any example to how to configur...
# multiplatform
b
Hello! Is out there any example to how to configure a KMM in a "convenient plugin"? I don't want to repeat the code inside the
build.gradle.kts
in all the modules for that reason I want to move all that to a gradle plugin. My problem is how to translate
val androidMain by getting
.
Once you've done the setup, you can add anything you want in convention plugins (I just add the plugin, but you can add your
android
block etc as well)
b
I see... I implementing it with
kt
instead of
kts
. Extending from `Plugin`:
Copy code
class KmpModule : Plugin<Project> {

    override fun apply(target: Project) {
...
c
You don't need to extend from plugin when writing convention plugins: https://docs.gradle.org/current/samples/sample_convention_plugins.html
a
super minor nitpick/clarification: a convention plugin can be a regular class that implements
Plugin<Project>
, or a pre-compiled script plugin. Either work fine, but pre-compiled script plugins are nice because they look more like regular
.gradle.kts
files. The quick-guide for creating convention plugins is: 1. create a ./buildSrc dir 2. in
./buildSrc/build.gradle.kts
make sure to apply the kotlin-dsl plugin 3. also in
./buildSrc/build.gradle.kts
add the Gradle plugins you want to use in conventions. Make sure to use the Maven coordinates (not the plugin ID) as implementation-dependencies. 4. Create a convention plugin in
./buildSrc/src/main/kotlin/my-convention.gradle.kts
5. in any subproject you can use your convention plugin in the plugins block with
id("my-convention")
c
Note that you should create a
buildSrc/settings.gradle.kts
too, even if you leave it empty