插件com.squareup. sql在Kotlin多平台的build.gradle中的应用

tyky79it  于 12个月前  发布在  Kotlin
关注(0)|答案(1)|浏览(128)

今天我在Android Studio Hedgehog中创建了一个空的Kotlin多平台应用**| 2023.1.1**我只在shared文件夹的build.gradle的插件部分添加了一行:

id("com.squareup.sqldelight") version "1.5.5"

字符串
按下同步按钮后,我得到了一个错误

shared/build.gradle.kts:9:5: Unresolved reference: androidTarget


我敢肯定,这不是错误的初始文件结构,这是关于sqldelight插件行本身-坏语法或这样。作为参考,我在这里留下一些文件:
build.gradle.kts共享文件夹(仅第一行):

plugins {
        alias(libs.plugins.kotlinMultiplatform)
        alias(libs.plugins.androidLibrary)
        id("com.squareup.sqldelight") version "1.5.5"//this line was added only
    }
    
    kotlin {
        androidTarget {
            compilations.all {
                kotlinOptions {
                    jvmTarget = "1.8"
                }
            }
        }
....


项目build.gradle.kts(全线):

plugins {
    //trick: for the same plugin versions in all sub-modules
    alias(libs.plugins.androidApplication).apply(false)
    alias(libs.plugins.androidLibrary).apply(false)
    alias(libs.plugins.kotlinAndroid).apply(false)
    alias(libs.plugins.kotlinMultiplatform).apply(false)
}


libs.versions.toml(所有线路)

[versions]
agp = "8.2.0"
kotlin = "1.9.20"
compose = "1.5.4"
compose-compiler = "1.5.4"
compose-material3 = "1.1.2"
androidx-activityCompose = "1.8.0"

[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }
compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "compose-material3" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
androidLibrary = { id = "com.android.library", version.ref = "agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }


我还尝试了另一种语法与该插件,在build.gradle的共享我添加

alias(libs.plugins.sqldelightPlugin)


libs.versions.toml中,

[versions]
....
sqldelight = "1.5.5"

[plugins]
....
sqldelightPlugin = { id = "com.squareup.sqldelight", version.ref = "sqldelight" }


但无论如何,我还是犯了同样的错误。
如何正确将com.squareup.sqldelight插件添加到Kotlin多平台项目的共享build.gradle中?

kmb7vmvb

kmb7vmvb1#

最新版本

对于最新版本,用途:

plugins {
   id("app.cash.sqldelight") version "2.0.1"
}

字符串
参见documentation

旧版本

在1.5.5版本结束时,他们在不同的插件ID下发布了它,而不是在Gradle插件门户上。如果你必须使用1.5.5,你需要用途:

buildscript {
  repositories {
    google()
    mavenCentral()
  }
  dependencies {
    classpath("com.squareup.sqldelight:gradle-plugin:1.5.5")
  }
}

apply(plugin = "com.squareup.sqldelight")


参见old documentation

相关问题