我正在编写一个简单的控制台应用程序,它应该在执行时生成一些 kotlin 代码。我遇到了一个奇怪的问题,我无法添加 KotlinPoen 依赖项。我的 build.gradle:
plugins {
id 'java-library'
id 'kotlin'
}
java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation group: 'com.squareup', name: 'kotlinpoet', version: '1.7.2'
}
但在 PoetApp.kt 导入失败并显示消息Unresolved reference: squareup
:
import com.squareup.kotlinpoet.FunSpec
object PoetApp {
@JvmStatic
fun main(vararg param: String) {
val main = FunSpec.builder("main")
.addCode("""
|var total = 0
|for (i in 0 until 10) {
| total += i
|}
|""".trimMargin())
.build()
}
}