提问人:user3617992 提问时间:11/15/2023 更新时间:11/15/2023 访问量:23
即使在 build.gradle.kts 中声明依赖项后也无法导入依赖项
Cannot import dependency even after declaring it in build.gradle.kts
问:
我正在使用 Kotlin/Native 开始一个新项目。一切正常,但现在我决定要番石榴的 ImmutableDoubleArray 类。所以我在我的build.gradle.kts文件中包含了依赖项,并尝试导入com.google.common.collect.ImmutableDoubleArray
不幸的是,现在构建失败,并显示错误消息“未解析的引用:com”
似乎正确检测到依赖项(因为 gradle 下载了相应的 jar 文件),但不知何故我无法在我的代码中引用它。有什么想法吗?
我在gradle-8.4上,目前还没有使用IDE。(在 emacs 中编码...我使用命令行开始构建,但这也无济于事。我什至删除了我的 ~/.gradle 目录,让 grade 从头开始下载所有内容,这无济于事。gradle --refresh-dependencies clean build
一切都很好:kotlinx.collections.immutable.*
import kotlinx.collections.immutable.* // works
import com.google.common.primitives.ImmutableDoubleArray // doesn't, undefined reference: com
这是我的 build.gradle.kts 文件:
plugins {
java
id("java-library")
kotlin("multiplatform") version "1.9.20"
}
repositories {
mavenCentral()
}
dependencies {
// 1. Use Guava in your implementation only:
implementation("com.google.guava:guava:32.1.3-jre")
// 2. Use Guava types in your public API:
//api("com.google.guava:guava:32.1.3-jre")
}
kotlin {
jvm("jvm") {
compilations.all {
kotlinOptions {
jvmTarget = "21"
}
}
}
linuxX64("linux")
mingwX64("windows")
targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
binaries {
sharedLib {
baseName = if(name == "windows") "libnative" else "native"
}
}
}
sourceSets {
get("commonMain").apply {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.6")
implementation("com.google.guava:guava:32.1.3-jre")
}
}
get("commonTest").apply {
dependencies {
implementation(kotlin("test"))
}
}
get("windowsMain").apply {
dependsOn(sourceSets["commonMain"])
}
get("windowsTest").apply {
dependsOn(sourceSets["commonTest"])
}
get("linuxMain").apply {
dependsOn(sourceSets["commonMain"])
}
get("linuxTest").apply {
dependsOn(sourceSets["commonTest"])
}
get("jvmMain").apply {
dependsOn(sourceSets["commonMain"])
}
get("jvmTest").apply {
dependsOn(sourceSets["commonTest"])
}
}
}
tasks.withType<Wrapper> {
gradleVersion = "8.4"
distributionType = Wrapper.DistributionType.ALL
}
tasks.named<Test>("jvmTest") {
useJUnitPlatform()
filter {
isFailOnNoMatchingTests = false
}
testLogging {
showExceptions = true
showStandardStreams = true
events = setOf(
org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED,
org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
)
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
答: 暂无答案
评论