Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
499 views
in Technique[技术] by (71.8m points)

signing - Why is this a receiver type mismatch when it seems to match what I see in the Gradle docs?

I'm converting a build from Buildr to Gradle.

So far I have the following build script:

repositories {
    jcenter()
}

allprojects {
    version = "0.8.1-SNAPSHOT"
    group = "org.trypticon.hex"
}

subprojects {
    apply(plugin = "java-library")
    apply(plugin = "maven-publish")
    apply(plugin = "signing")

    configure<JavaPluginExtension> {
        sourceCompatibility = JavaVersion.VERSION_11
        withJavadocJar()
        withSourcesJar()
    }

    dependencies {
        "testImplementation"("junit:junit:4.13")
    }

    configure<PublishingExtension> {
        repositories {
            maven {
                url = uri(if (version.toString().contains("SNAPSHOT")) {
                    "https://oss.sonatype.org/content/repositories/snapshots"
                } else {
                    "https://oss.sonatype.org/service/local/staging/deploy/maven2"
                })
                credentials {
                    username = System.getenv("DEPLOY_USER")
                    password = System.getenv("DEPLOY_PASS")
                }
            }
        }
        publications {
            register<MavenPublication>("mavenJava") {
                pom {
                    // omitting a bunch of metadata unrelatted to the issue
                }
            }
        }
    }

    configure<SigningExtension> {
        sign(publishing.publications["mavenJava"])
    }
}

When I try to build, I get this:

build.gradle.kts:124:14: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public val PluginDependenciesSpec.publishing: PluginDependencySpec defined in org.gradle.kotlin.dsl

IntelliJ says that the types match and shows no error.

I started with code from the Gradle docs which said to use this:

    signing {
        sign(publishing.publications["mavenJava"])
    }

But that fails when inside a subprojects block.

Using:

  • Gradle 6.8
  • Java 11.0.3

Further investigation:

I tried splitting the lines out to see exactly which bit the issue was on.

        configure<SigningExtension> {
            val e: PublishingExtension = publishing
            val p: Publication = e.publications["mavenJava"]
            sign(p)
        }

The error points directly at publishing on the first line. Hovering over it in IDEA, it helpfully tells me that Project.publishing is a PublishingExtension, so the call shows no error. Now the question is, why is it fine when inspecting the file, but fails at runtime? I thought this was exactly the kind of thing switching to Kotlin was going to stop. :(


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...