Damon
Damon

Reputation: 219

On a Compose Multiplatform gradle plugin, how can I include desktop configuration?

I am making my first Compose Multiplatform app, I want to organise my codebase with multiple modules. To do that I am creating gradle plugins with build-logic, I found an article explaining how to do that for a CMM project (I had already done that for some Android projects) but it is for an Android and iOS project. I followed those steps anyway, but now Ican't find a way to include desktop configuration.

Has anyone done that or knows where I could find this info ?

To see the project's convention plugins, check this repository.

Upvotes: 2

Views: 279

Answers (1)

GreatTusk
GreatTusk

Reputation: 95

Through trial and error, I found a solution that seems to work for configuring desktop settings:

class DesktopApplicationConventionPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        with(target) {
            afterEvaluate {
                extensions.configure<ComposeExtension> {
                    this.extensions.configure<DesktopExtension> {
                        application {
                            mainClass = "com.app.MainKt"

                            nativeDistributions {
                                targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
                                packageName = "com.app"
                                packageVersion = "1.0.0"
                            }
                        }

                    }
                }
            }
        }
    }
}

What I've observed:

  • Without afterEvaluate, ComposeExtension isn't found in registered extensions
  • DesktopExtension is only found inside ComposeExtension

This solution works, but I haven't found any documentation explaining why this specific structure is necessary. Would appreciate insights from others who understand Gradle plugin development better.

EDIT:

afterEvaluate is not necessary. The problem was that I was applying my convention plugins in the wrong order. For DesktopExtension to be discoverable, it's imperative to apply first the compose plugins, as the desktop settings can only be found inside the compose. block.

Upvotes: 0

Related Questions