build.gradle 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. plugins {
  2. id "com.google.protobuf" version "0.8.19"
  3. id 'java-library'
  4. }
  5. group 'com.incubator.message'
  6. version '1.0-SNAPSHOT'
  7. dependencies {
  8. testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
  9. testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.0'
  10. api 'com.alibaba.fastjson2:fastjson2:2.0.53'
  11. api 'com.google.protobuf:protobuf-java:4.28.3'
  12. api 'io.grpc:grpc-all:1.68.1'
  13. }
  14. protobuf {
  15. // 配置 Protocol Buffers 编译器版本
  16. protoc {
  17. artifact = 'com.google.protobuf:protoc:4.28.3'
  18. }
  19. // 配置 gRPC 插件
  20. plugins {
  21. grpc {
  22. artifact = 'io.grpc:protoc-gen-grpc-java:1.68.1'
  23. }
  24. }
  25. // 自动为所有 proto 生成 Java 和 gRPC 代码
  26. generateProtoTasks {
  27. all().forEach {
  28. it.plugins {
  29. grpc {}
  30. }
  31. }
  32. }
  33. }
  34. sourceSets {
  35. main {
  36. java {
  37. // 将生成的代码目录添加到主代码源路径
  38. srcDirs 'build/generated/source/proto/main/grpc'
  39. srcDirs 'build/generated/source/proto/main/java'
  40. }
  41. }
  42. }
  43. tasks {
  44. // 为构建任务添加依赖
  45. build.dependsOn("generateProto")
  46. // 配置测试任务,启用 JUnit 平台
  47. test {
  48. useJUnitPlatform()
  49. testLogging {
  50. events("PASSED", "FAILED", "SKIPPED")
  51. }
  52. }
  53. }