0

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.

lotdrops
  • 300
  • 5
  • 16
  • 1
    I think we'll really need to see the configs in full. – Kevin Galligan Apr 12 '21 at 22:00
  • If edited the question adding a repository with the project @KevinGalligan – lotdrops Apr 16 '21 at 18:37
  • I'll take a look, although ping me again if you don't hear anything back after the weekend... – Kevin Galligan Apr 16 '21 at 22:56
  • I'm stuck just opening the project https://gist.github.com/kpgalligan/5e01aa9aad45b1c44a2d7e1a55726820 – Kevin Galligan Apr 17 '21 at 16:37
  • Thank you for helping with this @KevinGalligan I forgot to mention that I use Android Studio Canary 9. In newer versions it does not work (I have to adapt it). And in older versions it probably does not work either. Is it possible that it is because of this that it won't open? – lotdrops Apr 18 '21 at 10:06
  • I have pushed a branch "newer_as" that works with canary 14 in case that's better for you (disabling some compiler options that I'm not sure if they will be needed). I can try removing compose entirely if thats what doesn't let you open the project – lotdrops Apr 18 '21 at 10:30
  • Hi @KevinGalligan have you been able to look into this? – lotdrops May 15 '21 at 10:13
  • It's still failing. ```An exception occurred applying plugin request [id: 'com.android.application'] > Failed to apply plugin 'com.android.internal.application'. > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8. You can try some of the following options: - changing the IDE settings. - changing the JAVA_HOME environment variable. - changing `org.gradle.java.home` in `gradle.properties`.``` – Kevin Galligan May 18 '21 at 16:22
  • Sorry about the bad formatting :) I'm not sure why, but I don't want to try to debug the project config. It's saying I'm on Java 1.8 but I'm running 11. Canary 14. – Kevin Galligan May 18 '21 at 16:23
  • have you tried building the database? `gradlew ./build` – chia yongkang Jun 17 '21 at 02:29

1 Answers1

2

tldr;

According to your current repository structure, you have the sqldelight directory inside src/commonMain/kotlin. It should however be on the same level with kotlin, in your situation /shared/database/src/commonMain/sqldelight.

Full answer

Each gradle module has it's own build.gradle.kts file. The one that loads the plugin com.squareup.sqldelight is also the one that will look into the according source files. With that said, if you want your .sq files to be in your :shared:database module, you have to check the following parts:

  1. the sqldelight plugin is included in /shared/database/build.gradle.kts
  2. The sqldelight is configured in /shared/database/build.gradle.kts
  3. Inside the configuration of sqldelight there is the option to override the default source folder which is sqldelight with the sourceFolders attribute. By default and with he above configuration it is /shared/database/src/commonMain/sqldelight
  4. Inside the configured source folder, you have to use the package structure defined in the configuration (like with packageName com.example you would have the directory /shared/database/src/commonMain/sqldelight/com/example/MySQLFile.sq (not very sure about this step though)
malliaridis
  • 389
  • 1
  • 12