KmpComposeUIViewControllerPlugin

class KmpComposeUIViewControllerPlugin : Plugin<Project>

Heavy lifts Gradle configurations when using KMP-ComposeUIViewController library.

Exposes the following tasks under the composeuiviewcontroller group:

  • exportToSpm — default. Creates and maintains a local SPM package at iosApp/Representables/ (folder names driven by PluginParameters.iosAppFolderName and PluginParameters.exportFolderName). Triggered automatically after embedAndSignAppleFrameworkForXcode, embedSwiftExportForXcode, or syncFramework when PluginParameters.autoExport is true. Not registered when PluginParameters.legacyMode is true. Requires a one-time setup via createRepresentablesPackage (the plugin warns automatically if this hasn't been run yet).

  • createRepresentablesPackage — one-time setup for the SPM package: creates the stub Package.swift and adds the package reference to the Xcode project. Not registered when PluginParameters.legacyMode is true.

  • deleteRepresentablesPackage — reverses createRepresentablesPackage. Always manual — never run automatically.

  • copyFilesToXcode — legacy. Syncs KSP-generated Swift Representables to iosApp/Representables/ and updates the Xcode project references by manipulating project.pbxproj directly on every build. Only registered when PluginParameters.legacyMode is true.

  • formatSwiftFiles — formats generated .swift files with swiftformat default rules (if available).

  • validateRepresentables — inspects the full Representables pipeline without triggering a build. Useful for diagnosing why Xcode cannot find generated UIViewControllerRepresentable files. Run it with ./gradlew validateRepresentables. Reports OK, WARN, or FAIL for each check, adapting to whichever mode (PluginParameters.legacyMode or the default SPM mode) is active:

CheckWhat it verifiesFails when
KSP output.swift files exist in build/generated/ksp/KSP never ran or failed mid-generation
Destination.swift files exist in iosApp/Representables/ (or Sources/ in SPM mode)Export task did not run
SyncKSP output and destination contain the same filesFiles are stale or missing
xcodeproj / Package.swiftRepresentables are referenced in project.pbxproj (legacy) or Package.swift exists (SPM)Setup step failed

WARN entries (stale destination files, xcodeproj/Package.swift not found) do not fail the task. FAIL entries throw a GradleException listing all errors. The most common fix is ./gradlew clean. The reference check is skipped when PluginParameters.autoExport is false.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open override fun apply(project: Project)