Sqldelight: Support Kotlin Gradle DSL

Created on 12 Mar 2019  路  5Comments  路  Source: cashapp/sqldelight

This: fun methodMissing(name: String, args: Any): Any is not practical to use with Kotlin Gradle DSL.
This is also not typesafe.

gradle-plugin enhancement

Most helpful comment

For anyone wanting to use the SqlDelight Gradle plugin from Gradle Kotlin DSL until this issue is solved, here's a small example that should work:

sqldelight {
    methodMissing("MyDatabase", arrayOf(closureOf<SqlDelightDatabase> {
        packageName = "com.example.db"
        sourceFolders = listOf("db")
        schemaOutputDirectory = file("build/dbs")
        dependency project(":OtherProject")
    }))
}

All 5 comments

For anyone wanting to use the SqlDelight Gradle plugin from Gradle Kotlin DSL until this issue is solved, here's a small example that should work:

sqldelight {
    methodMissing("MyDatabase", arrayOf(closureOf<SqlDelightDatabase> {
        packageName = "com.example.db"
        sourceFolders = listOf("db")
        schemaOutputDirectory = file("build/dbs")
        dependency project(":OtherProject")
    }))
}

Does anyone have a build.gradle.kts example? I can't get the sqldelight stanza to even be accepted although the plugin appears to have been loaded.

@nwillc My example shown above should work. Note that you need to have this enableFeaturePreview("GRADLE_METADATA") in your settings.gradle.kts for it to work as it's still need for Kotlin multiplatform for now.

I think adding an extension method would suffice for now. How does this look?

fun SqlDelightExtension.createDataBase(dataBaseName: String, configuration: SqlDelightDatabase.() -> Unit) {
    methodMissing(dataBaseName, arrayOf(closureOf(configuration)))
}
sqldelight {
    createDataBase("Database") {
        packageName = "com.example.pacakge"
    }
}

Fixed by #1306

Was this page helpful?
0 / 5 - 0 ratings