I have modularized my shared code, so currently I have a shared module (kmp), and inside this module I have shared:core and shared:database (both multiplatform too).
If I set up the database in the shared module it works: I place my AppDatabase.sq in the commonMain folder in shared, in sqldelight/com/example/kmmbase/database/ and the schema is correctly generated.
On the other hand, if I try to move it to the shared:database module it does not generate the schema, and the driver won't compile. I add the AppDatabase.sq file to the same path but now in the commonMain of the shared:database module, and I move the sqldelight plugin and gradle config from the shared gradle file to the shared:database gradle file.
The gradle config I have is as follows:
sqldelight {
database("AppDatabase") {
packageName = "com.example.kmmbase.database"
sourceFolders = listOf("sqldelight")
}
}
I've tried different locations for the .sq file, and on each one I match the gradle config's packageName:
- sqldelight/com/example/kmmbase/shared/
- sqldelight/com/example/kmmbase/database/
- sqldelight/com/example/database/
- sqldelight/com/example/database/database/
- sqldelight/database/
- ...
Any idea of what I could be doing wrong?
Edit: here's a repo with the code.
tldr;
According to your current repository structure, you have the
sqldelightdirectory insidesrc/commonMain/kotlin. It should however be on the same level withkotlin, in your situation/shared/database/src/commonMain/sqldelight.Full answer
Each gradle module has it's own
build.gradle.ktsfile. The one that loads the plugincom.squareup.sqldelightis also the one that will look into the according source files. With that said, if you want your.sqfiles to be in your:shared:databasemodule, you have to check the following parts:sqldelightplugin is included in/shared/database/build.gradle.ktssqldelightis configured in/shared/database/build.gradle.ktssqldelightthere is the option to override the default source folder which issqldelightwith thesourceFoldersattribute. By default and with he above configuration it is/shared/database/src/commonMain/sqldelightcom.exampleyou would have the directory/shared/database/src/commonMain/sqldelight/com/example/MySQLFile.sq(not very sure about this step though)