1 year ago

#361664

test-img

Rajkumar Natarajan

Unresolved reference.None of the following candidates is applicable because of receiver type mismatch: when using protobuf plugin in gradle kotlin dsl

I'm using com.google.protobuf gradle plugin in my project for generating java classes from proto files. Below is my build.gradle which works fine.


buildscript {
  repositories {
    mavenCentral()
    mavenLocal()
  }
  dependencies {
    classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.18'
  }
}
plugins {
    id 'java'
    id 'com.google.protobuf' version '0.8.18'
}
repositories {
    mavenCentral()
    mavenLocal()
}
group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}
dependencies {
    implementation('io.grpc:grpc-netty-shaded:1.45.1')
    implementation('io.grpc:grpc-stub:1.45.1')
    implementation('io.grpc:grpc-protobuf:1.45.1')
    implementation 'javax.annotation:javax.annotation-api:1.3.2'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

test {
    useJUnitPlatform()
}

protobuf {
  protoc {
    artifact = "com.google.protobuf:protoc:3.20.0"
  }
  plugins {
    grpc {
      artifact = 'io.grpc:protoc-gen-grpc-java:1.45.1'
    }
  }
  generateProtoTasks {
    all()*.plugins {
      grpc {}
    }
  }
}

I'm rewriting the build into kotlin dsl as below -

import com.google.protobuf.gradle.protoc

buildscript {
    repositories {
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath ("com.google.protobuf:protobuf-gradle-plugin:0.8.18")
    }
}
plugins {
    java
    id("com.google.protobuf") version "0.8.18"
}
repositories {
    mavenCentral()
    mavenLocal()
    gradlePluginPortal()
}
group = "org.example"
version = "1.0-SNAPSHOT"


dependencies {
    implementation("io.grpc:grpc-netty-shaded:1.45.1")
    implementation("io.grpc:grpc-stub:1.45.1")
    implementation("io.grpc:grpc-protobuf:1.45.1")
//    implementation("org.apache.tomcat:annotations-api:6.0.53")
    implementation("javax.annotation:javax.annotation-api:1.3.2")
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}

tasks.getByName<Test>("test") {
    useJUnitPlatform()
}

protobuf {

    protoc {
        artifact = "com.google.protobuf:protoc:3.20.0"
    }
    plugins {
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:1.45.1"
        }
    }
    generateProtoTasks {
        all()*.plugins {
            grpc {}
        }
    }
}

when I do gradle clean compileJava I get below error -

$ gradle clean compileJava

Configure project : e: /home/rajkumar/Coding/java/grpc/grpc-complete-course/grpc-gradle-kts-demo/build.gradle.kts:50:15: Expecting an element e: /home/rajkumar/Coding/java/grpc/grpc-complete-course/grpc-gradle-kts-demo/build.gradle.kts:41:5: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public fun ProtobufConfigurator.protoc(action: ExecutableLocator.() -> Unit): Unit defined in com.google.protobuf.gradle e: /home/rajkumar/Coding/java/grpc/grpc-complete-course/grpc-gradle-kts-demo/build.gradle.kts:45:9: Unresolved reference: grpc e: /home/rajkumar/Coding/java/grpc/grpc-complete-course/grpc-gradle-kts-demo/build.gradle.kts:46:13: Unresolved reference: artifact e: /home/rajkumar/Coding/java/grpc/grpc-complete-course/grpc-gradle-kts-demo/build.gradle.kts:49:5: Unresolved reference: generateProtoTasks e: /home/rajkumar/Coding/java/grpc/grpc-complete-course/grpc-gradle-kts-demo/build.gradle.kts:50:9: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public inline fun Array<out TypeVariable(T)>.all(predicate: (TypeVariable(T)) -> Boolean): Boolean defined in kotlin.collections public inline fun BooleanArray.all(predicate: (Boolean) -> Boolean): Boolean defined in kotlin.collections public inline fun ByteArray.all(predicate: (Byte) -> Boolean): Boolean defined in kotlin.collections public inline fun CharArray.all(predicate: (Char) -> Boolean): Boolean defined in kotlin.collections public inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean defined in kotlin.text public inline fun DoubleArray.all(predicate: (Double) -> Boolean): Boolean defined in kotlin.collections public inline fun FloatArray.all(predicate: (Float) -> Boolean): Boolean defined in kotlin.collections public inline fun IntArray.all(predicate: (Int) -> Boolean): Boolean defined in kotlin.collections public inline fun LongArray.all(predicate: (Long) -> Boolean): Boolean defined in kotlin.collections public inline fun ShortArray.all(predicate: (Short) -> Boolean): Boolean defined in kotlin.collections public inline fun UByteArray.all(predicate: (UByte) -> Boolean): Boolean defined in kotlin.collections public inline fun UIntArray.all(predicate: (UInt) -> Boolean): Boolean defined in kotlin.collections public inline fun ULongArray.all(predicate: (ULong) -> Boolean): Boolean defined in kotlin.collections public inline fun UShortArray.all(predicate: (UShort) -> Boolean): Boolean defined in kotlin.collections public inline fun Iterable<TypeVariable(T)>.all(predicate: (TypeVariable(T)) -> Boolean): Boolean defined in kotlin.collections public inline fun <K, V> Map<out TypeVariable(K), TypeVariable(V)>.all(predicate: (Map.Entry<TypeVariable(K), TypeVariable(V)>) -> Boolean): Boolean defined in kotlin.collections public inline fun Sequence<TypeVariable(T)>.all(predicate: (TypeVariable(T)) -> Boolean): Boolean defined in kotlin.sequences public inline fun ComponentMetadataHandler.all(): ComponentMetadataHandler defined in org.gradle.kotlin.dsl public inline fun ComponentMetadataHandler.all(rule: KClass): ComponentMetadataHandler defined in org.gradle.kotlin.dsl public inline fun ComponentMetadataHandler.all(rule: KClass, configureAction: Action): ComponentMetadataHandler defined in org.gradle.kotlin.dsl public inline fun ComponentMetadataHandler.all(configureAction: Action): ComponentMetadataHandler defined in org.gradle.kotlin.dsl e: /home/rajkumar/Coding/java/grpc/grpc-complete-course/grpc-gradle-kts-demo/build.gradle.kts:51:13: Unresolved reference: grpc

FAILURE: Build failed with an exception.

  • Where: Build file '/home/rajkumar/Coding/java/grpc/grpc-complete-course/grpc-gradle-kts-demo/build.gradle.kts' line: 50

  • What went wrong: Script compilation errors:

    Line 50: all()*.plugins { ^ Expecting an element

    Line 41: protoc { ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public fun ProtobufConfigurator.protoc(action: ExecutableLocator.() -> Unit): Unit defined in com.google.protobuf.gradle

    Line 45: grpc { ^ Unresolved reference: grpc

    Line 46: artifact = "io.grpc:protoc-gen-grpc-java:1.45.1" ^ Unresolved reference: artifact

    Line 49: generateProtoTasks { ^ Unresolved reference: generateProtoTasks

    Line 50: all()*.plugins { ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public inline fun Array<out TypeVariable(T)>.all(predicate: (TypeVariable(T)) -> Boolean): Boolean defined in kotlin.collections public inline fun BooleanArray.all(predicate: (Boolean) -> Boolean): Boolean defined in kotlin.collections public inline fun ByteArray.all(predicate: (Byte) -> Boolean): Boolean defined in kotlin.collections public inline fun CharArray.all(predicate: (Char) -> Boolean): Boolean defined in kotlin.collections public inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean defined in kotlin.text public inline fun DoubleArray.all(predicate: (Double) -> Boolean): Boolean defined in kotlin.collections public inline fun FloatArray.all(predicate: (Float) -> Boolean): Boolean defined in kotlin.collections public inline fun IntArray.all(predicate: (Int) -> Boolean): Boolean defined in kotlin.collections public inline fun LongArray.all(predicate: (Long) -> Boolean): Boolean defined in kotlin.collections public inline fun ShortArray.all(predicate: (Short) -> Boolean): Boolean defined in kotlin.collections public inline fun UByteArray.all(predicate: (UByte) -> Boolean): Boolean defined in kotlin.collections public inline fun UIntArray.all(predicate: (UInt) -> Boolean): Boolean defined in kotlin.collections public inline fun ULongArray.all(predicate: (ULong) -> Boolean): Boolean defined in kotlin.collections public inline fun UShortArray.all(predicate: (UShort) -> Boolean): Boolean defined in kotlin.collections public inline fun Iterable<TypeVariable(T)>.all(predicate: (TypeVariable(T)) -> Boolean): Boolean defined in kotlin.collections public inline fun <K, V> Map<out TypeVariable(K), TypeVariable(V)>.all(predicate: (Map.Entry<TypeVariable(K), TypeVariable(V)>) -> Boolean): Boolean defined in kotlin.collections public inline fun Sequence<TypeVariable(T)>.all(predicate: (TypeVariable(T)) -> Boolean): Boolean defined in kotlin.sequences public inline fun ComponentMetadataHandler.all(): ComponentMetadataHandler defined in org.gradle.kotlin.dsl public inline fun ComponentMetadataHandler.all(rule: KClass): ComponentMetadataHandler defined in org.gradle.kotlin.dsl public inline fun ComponentMetadataHandler.all(rule: KClass, configureAction: Action): ComponentMetadataHandler defined in org.gradle.kotlin.dsl public inline fun ComponentMetadataHandler.all(configureAction: Action): ComponentMetadataHandler defined in org.gradle.kotlin.dsl

    Line 51: grpc {} ^ Unresolved reference: grpc

7 errors

  • Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

BUILD FAILED in 2s

How can I fix the error? I don't know how to do that in kotlin dsl?

gradle

gradle-kotlin-dsl

protobuf-java

0 Answers

Your Answer

Accepted video resources