https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
b

Brais Gabin

03/14/2023, 10:12 AM
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

Brais Gabin

03/14/2023, 10:21 AM
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

CLOVIS

03/14/2023, 10:22 AM
You don't need to extend from plugin when writing convention plugins: https://docs.gradle.org/current/samples/sample_convention_plugins.html
a

Adam S

03/14/2023, 12:00 PM
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

CLOVIS

03/14/2023, 12:09 PM
Note that you should create a
buildSrc/settings.gradle.kts
too, even if you leave it empty
9 Views