0

I have been trying to follow GitHub tutorial to publish a package. The problem is that I get the following error when trying to run 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

For some reason, the "from" keyword is not recognized.

Here is my build.gradle.kts script:

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"])
        }
    }

How can I fix this?

J.Paravicini
  • 882
  • 12
  • 39

1 Answers1

2

You did not provide the type of publication, so you use just a basic Publication. from() is a function of MavenPublication, so you need to explicitly specify that you need a MavenPublication:

publications {
    register<MavenPublication>("gpr") {
        from(components["java"])
    }
}
broot
  • 21,588
  • 3
  • 30
  • 35
  • Hmm, Idk, why I thought from, was a keyword. That worked, but I still think the documentation should reflect that. Thanks for the answer ^^ – J.Paravicini May 22 '21 at 13:00
  • All examples in the documentation about publishing ([link1](https://docs.gradle.org/current/userguide/publishing_setup.html) [link2](https://docs.gradle.org/current/userguide/publishing_maven.html)) specify the type of publication for both Kotlin and Gradle DSL. Maybe in the past it wasn't required and then it has changed, idk. Also, I believe there are no special keywords in Gradle build files. There are keywords of Kotlin/Gradle and only functions and properties. – broot May 22 '21 at 13:18
  • Maybe it was taken from https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry#example-using-kotlin-dsl-for-a-single-package-in-the-same-repository , which doesn't specify types (they are in the docs source code but tags < > are cut away by renderer) – Lutosław Jun 25 '21 at 09:24