我在一个项目中使用下面提到的protobuf gradle插件,在该项目中它可以正常工作,但是当我在另一个项目中引用相同的插件时,“gradle clean”始终给我复制以下错误:
build.grade(v3.4)的相关部分
apply plugin: 'com.google.protobuf'
buildscript {
repositories {
mavenCentral()
mavenLocal()
jcenter()
}
dependencies {
// classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.9"
// classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'
}
}
def grpcVersion = '1.1.2'
dependencies {
compile "io.grpc:grpc-netty:${grpcVersion}"
compile "io.grpc:grpc-protobuf:${grpcVersion}"
compile "io.grpc:grpc-stub:${grpcVersion}"
}
protobuf {
protoc {
Artifact = 'com.google.protobuf:protoc:3.2.0'
}
plugins {
grpc {
Artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks {
all()*.plugins {
grpc {
// To generate deprecated interfaces and static bindService method,
// turn the enable_deprecated option to true below:
option 'enable_deprecated=false'
}
}
}
}
运行gradle clean 时出现错误
* What went wrong:
Could not compile build file '/xyz/xyz/build.gradle'.
> startup failed:
build file '/xyz/xyz/build.gradle': 102: you tried to assign a value to the class 'org.gradle.api.component.Artifact'
@ line 102, column 9.
Artifact = 'com.google.protobuf:protoc:3.2.0'
^
build file '/xyz/xyz/build.gradle': 106: you tried to assign a value to the class 'org.gradle.api.component.Artifact'
@ line 106, column 13.
Artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
我已经尝试了protobuf插件0.8.0。和0.8.1,但都给出相同的错误。 v0.8.0与其他项目一样。关于如何进一步解决此问题的任何想法,将不胜感激。
最佳答案
应该是artifact
,而不是Artifact
。后者是您尝试分配给它的类,它将不起作用,前者是您分配给它的属性。
关于gradle - gradle protobuf插件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43186174/