找不到 Kotlin DSL "from" 关键字

Kotlin DSL "from" keyword not found

我一直在努力跟着GitHub tutorial发布一个包。问题是我在尝试 运行 Gradle:

时收到以下错误
Script compilation error:

Line 49:           from(components["java"])
                   ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
                       public inline fun <reified T : VersionControlSpec> VcsMapping.from(noinline configureAction: TypeVariable(T).() -> Unit): Unit defined in org.gradle.kotlin.dsl
                       public inline fun <T : VersionControlSpec> VcsMapping.from(type: KClass<TypeVariable(T)>, configureAction: Action<in TypeVariable(T)>): Unit defined in org.gradle.kotlin.dsl

由于某种原因,无法识别“来自”关键字。

这是我的 build.gradle.kts 脚本:

plugins {
    id("org.jetbrains.kotlin.jvm") version "1.5.0"
    `java-library`
    `maven-publish`
}

repositories {
    mavenCentral()
}

dependencies {
    implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("com.google.guava:guava:30.0-jre")
    testImplementation("org.jetbrains.kotlin:kotlin-test")
    testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
    api("org.apache.commons:commons-math3:3.6.1")
}

publishing {
    repositories {
        maven {
            name = "GitHubPackages"
            url = uri("https://maven.pkg.github.com/jorgeparavicini/draughts")
            credentials {
                username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
                password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
            }
        }
    }
    publications {
        register("gpr") {
            from(components["java"])
        }
    }

我该如何解决这个问题?

您没有提供出版物的类型,所以您只使用基本的 Publicationfrom()MavenPublication的一个函数,所以需要明确指定需要一个MavenPublication:

publications {
    register<MavenPublication>("gpr") {
        from(components["java"])
    }
}