plugins { id "com.google.protobuf" version "0.8.19" id 'java-library' } group 'com.incubator.message' version '1.0-SNAPSHOT' dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0' api 'com.alibaba.fastjson2:fastjson2:2.0.53' api 'com.google.protobuf:protobuf-java:4.28.3' api 'io.grpc:grpc-all:1.68.1' } protobuf { // 配置 Protocol Buffers 编译器版本 protoc { artifact = 'com.google.protobuf:protoc:4.28.3' } // 配置 gRPC 插件 plugins { grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.68.1' } } // 自动为所有 proto 生成 Java 和 gRPC 代码 generateProtoTasks { all().forEach { it.plugins { grpc {} } } } } sourceSets { main { java { // 将生成的代码目录添加到主代码源路径 srcDirs 'build/generated/source/proto/main/grpc' srcDirs 'build/generated/source/proto/main/java' } } } tasks { // 为构建任务添加依赖 build.dependsOn("generateProto") }