https://kotlinlang.org logo
#touchlab-tools
Title
# touchlab-tools
r

Richard Leggett

09/21/2023, 2:57 PM
Hey folks, I was chatting with @kpgalligan about a use case we have with the brilliant SKIE and I'd love to share to see if there's anything we might be doing wrong, or whether there's something the library might do to support it.... 🧵
I'm writing some gradle plugins to apply conventions and configure a growing number of modules in our KMP app. In our KMP "export code" modules I'd like to apply the
SkieExtension
so we don't have to add the same
skie{}
block to multiple modules (we have different app flavors / shared .frameworks represented as different gradle modules). So it's something like this:
./my-exported-module/build.gradle.kts:
Copy code
plugins {
   id("com.domain.export.plugin")
   ...apply other plugins...
}

...rest of module gradle (but no need for skie {} block which is applied via above) ...
./build-logic/build.gradle.kts:
Copy code
plugins {
    `kotlin-dsl`
}

dependencies {
    compileOnly(libs.skie.gradlePlugin)
    compileOnly(libs.android.gradlePlugin)
    compileOnly(libs.kotlin.multiplatform.gradlePlugin)
...
}

gradlePlugin {
    plugins {
        create("com.domain.export.plugin", "MyExportPlugin")
    }
}
And we'd love to do this...
./build-logic/src/kotlin/MyExportPlugin.kts:
Copy code
open class MyExportPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        with(target) {
            val libs = the<LibrariesForLibs>()

            with(pluginManager) {
               apply(libs.plugins.skie.get().pluginId)
            }

            extensions.getByType<SkieExtension>().apply {
                analytics {
                    disableUpload.set(true)
                } etc...
            }
        }
    }
}
The problem is
SkieExtension
is not accessible in this context when depending on just the SKIE gradle plugin package.
What I did find is if I also include the AGP specific gradle plugin package I get
SkieExtension
and it works - so I wondered if this is the right approach, or whether this class could be api-exposed in the main plugin:
Copy code
skie-gradlePlugin = { module = "co.touchlab.skie:co.touchlab.skie.gradle.plugin", version.ref = "skie" }

# including this also gives us SkieExtension
skie-api-gradlePlugin = { module = "co.touchlab.skie:gradle-plugin-api-gradle_8.1", version.ref = "skie" }
f

Filip Dolník

09/21/2023, 3:15 PM
Hi! What you describe should be possible to do, so it’s probably just a bug in our plugin configuration. The thing with SKIE Gradle plugin is that the plugin (that you as a user add to your project) is actually just a loader for another plugin that configures SKIE. The plugin loader decides at runtime which SKIE plugin to apply depending on the used Kotlin version (to support different KMP versions). I’m not sure if we can add the dependency directly to the loader but right now I can’t think of a reason why it shouldn’t be possible. But if not (or until we fix it) you can probably just depend on the API module.
So I checked it and the loader in fact has a dependency on the API module
r

Richard Leggett

09/21/2023, 3:24 PM
Hey sounds great thanks Filip. Would love to know if you make a change, I'd be happy to test it again (and remove the workaround 🙂 )
f

Filip Dolník

09/21/2023, 3:24 PM
it’s just that it’s declared as
implementation
instead of
api
so that’s an easy change
done, it will be included in the 0.5.0 version which we will hopefully release next week
🙌 1
2 Views