我不知道我做错了什么。我遵循了许多指南,总是坚持在我的gradle kotlin build.gradle.kts
文件中protobuf
插件的protoc
插件调用的分辨率。
这是我的整个文件:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
dependencies {
classpath("com.google.protobuf:protobuf-gradle-plugin:0.8.14")
}
}
plugins {
id("com.google.protobuf") version "0.8.14"
id("org.springframework.boot") version "2.4.1"
id("io.spring.dependency-management") version "1.0.10.RELEASE"
kotlin("jvm") version "1.4.21"
kotlin("plugin.spring") version "1.4.21"
kotlin("plugin.jpa") version "1.4.21"
}
group = "com.myapp"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_15
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// gRPC
implementation( "io.grpc:grpc-protobuf:3.14.0")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.grpc:grpc-testing")
}
sourceSets {
main {
proto {
}
}
test {
proto {
}
}
}
protobuf {
protoc {
artifact("com.google.protobuf:protoc:0.8.14")
}
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "15"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
无论我做什么
protobuf {
protoc { // <<<
artifact("com.google.protobuf:protoc:0.8.14") // <<<
}
}
此部分无法解析,导致以下错误:
> Configure project :
Could not resolve: org.jetbrains.kotlin:kotlin-stdlib:1.4.21
e: /home/xetra11/Development/projects/user-service/build.gradle.kts:52:5: Unresolved reference: protoc
e: /home/xetra11/Development/projects/user-service/build.gradle.kts:53:9: Unresolved reference: artifact
我已经在Github上回答了这个问题。
您需要为协议导入com.google.protobuf.gradle.protoc
。
artifact
是协议定位器的属性(而不是函数),所以应该是artifact = "com.google.protobuf:protoc:0.8.14"
。