正在为Kotlin玩箭头库,并在文档https://arrow-kt.io/docs/optics/中发现了这个错误。我做错了什么?
Unresolved reference: company代码是下一个代码,因此由于引用中的错误,它没有编译。
package com.app
import arrow.optics.Optional
import arrow.optics.optics
@optics
data class Street(val number: Int, val name: String) {
companion object
}
@optics
data class Address(val city: String, val street: Street) {
companion object
}
@optics
data class Company(val name: String, val address: Address) {
companion object
}
@optics
data class Employee(val name: String, val company: Company) {
companion object
}
fun main() {
// an immutable value with very nested components
val john = Employee("John Doe", Company("Kategory", Address("Functional city", Street(42, "lambda street"))))
// an Optional points to one place in the value
val optional: Optional<Employee, String> = Employee.company.address.street.name
// and now you can modify into a new copy without nested 'copy's!
optional.modify(john, String::toUpperCase)
}下一个是我的依赖项。
//region Arrow
implementation("io.arrow-kt:arrow-core:$arrow_version")
implementation("io.arrow-kt:arrow-fx-coroutines:$arrow_version")
implementation("io.arrow-kt:arrow-optics:$arrow_version")
//endregion发布于 2022-06-10 13:24:58
您的分级配置似乎缺少一些所需的Google设置。您可以在网站的箭头光学装置部分和下面找到它。
plugins {
id("com.google.devtools.ksp") version "$googleKspVersion"
}
dependencies {
ksp("io.arrow-kt:arrow-optics-ksp-plugin:$arrowVersion")
}您还需要让IDEA知道生成的源代码,否则它将无法正确地提取代码突出显示和语法报告的代码。该设置在正式的Kotlin网站上进行了解释,如下所示。
kotlin {
sourceSets.main {
kotlin.srcDir("build/generated/ksp/main/kotlin")
}
sourceSets.test {
kotlin.srcDir("build/generated/ksp/test/kotlin")
}
}发布于 2022-07-27 20:56:03
在构建脚本中添加下面的代码(*.gradle.kts)。它将注册一个新的源dir,这样您的IDE将看到生成的扩展。不管您有多少口味和构建类型,这都是可行的。
android {
// ...
androidComponents.onVariants { variant ->
val name = variant.name
sourceSets {
getByName(name).kotlin.srcDir("${buildDir.absolutePath}/generated/ksp/${name}/kotlin")
}
}
}https://stackoverflow.com/questions/72574437
复制相似问题