cashapp / sqldelight

SQLDelight - Generates typesafe Kotlin APIs from SQL
https://cashapp.github.io/sqldelight/
Apache License 2.0
6.03k stars 503 forks source link

Incompatible with Kotlin 1.9.x #4523

Open softartdev opened 11 months ago

softartdev commented 11 months ago

SQLDelight Version

2.0.2

Operating System

macOS

Gradle Version

8.7

Kotlin Version

1.9.x

Dialect

SQLite

AGP Version

8.3.1

Describe the Bug

There was a build error after upgrading my pet-project to Kotlin 1.9.0. Reproducing on Github-Action CI: https://github.com/softartdev/NoteDelight/actions/runs/5842453316/job/15843597101#step:8:753

Stacktrace

Task :shared:compileIosMainKotlinMetadata FAILED e: file:///.../*.kt Unresolved reference: SqlDriver e: file:///.../*.kt Unresolved reference: SqlSchema e: file:///.../*.kt Unresolved reference: QueryResult

Gradle Build Script

plugins {
    alias(libs.plugins.kotlin.multiplatform)
    alias(libs.plugins.kotlin.cocoapods)
    alias(libs.plugins.sqlDelight)
    alias(libs.plugins.android.library)
    alias(libs.plugins.mokoResources)
}
android { … }
multiplatformResources { … }
kotlin {
    jvmToolchain(11)
    jvm()
    androidTarget()
    iosArm64()
    iosSimulatorArm64()
    applyDefaultHierarchyTemplate()

    sourceSets {
        commonMain.dependencies { … }
        commonTest.dependencies { … }
        androidMain { … }
        val androidUnitTest by getting { … }
        iosMain.dependencies {
            implementation(libs.sqlDelight.native)
        }
        jvmMain.dependencies { … }
        jvmTest.dependencies { … }
    }
    cocoapods {
        summary = "Common library for the NoteDelight app"
        homepage = "https://github.com/softartdev/NoteDelight"
        ios.deploymentTarget = "14.0"
        pod("SQLCipher", libs.versions.iosSqlCipher.get())
        framework {
            isStatic = true
            export(libs.mokoResources)
        }
    }
}
sqldelight {
    databases {
        create("NoteDb") {
            packageName.set("com.softartdev.notedelight.shared.db")
        }
    }
    linkSqlite.set(false)
}
softartdev commented 10 months ago

The error still occurs in Kotlin 1.9.10. Reproducing on Github-Action CI: https://github.com/softartdev/NoteDelight/actions/runs/6102440527/job/16560922473#step:8:604

frontiertsymbal commented 9 months ago

Hello. I received the same error on the iOS build. Are there any updates or workarounds? This error was present both with 1.8.20 (22) and with 1.9.10

softartdev commented 8 months ago

Same error reproducing with Kotlin 1.9.20: https://github.com/softartdev/NoteDelight/actions/runs/6723531752/job/18273806995#step:8:708

softartdev commented 7 months ago

I found a workaround. Whether you call the legacy ios() function, which is deprecated and creates intermediate source sets under the hood, or create them manually, you then need to call the applyDefaultHierarchyTemplate() function. At least it works for my project. The cause of the error may be related to the source sets.

softartdev commented 7 months ago

The error still occurs in sqldelight 2.0.1 https://github.com/softartdev/NoteDelight/actions/runs/7096127975/job/19314143203#step:8:697

vincent-paing commented 3 months ago

Did you ever found out an workaround for this? I'm having the same problem with kotlin 1.9.22

softartdev commented 3 months ago

The error still occurs in sqldelight 2.0.2 & kotlin 1.9.23. The previously found workaround still works.

AlexanderEggers commented 3 months ago

@softartdev Unfortunately that workaround doesn't work for me. I'm still getting the issue when compiling for more than one ios-related target. Using sqldelight 2.0 and kotlin 1.9.23. Do you have any ideas for a slightly different workaround?

softartdev commented 3 months ago

@AlexanderEggers Try the workaround for each module that includes iOS-targets. Anyway, this requires a deep dive into the codebase of the library and plugins, I have little time, so just have to wait for the official fix.

AlexanderEggers commented 2 months ago

I think I found a tmp fix working for me:

val development: String by rootProject.extra
    if (development == "true") {
        iosSimulatorArm64("ios")
    } else {
        iosArm64("ios")
    }

Depending on my gradle.properties I'm using a specific target and match all ios targets to the same name. That clashes with the default template but seems to be working in my case.