build.gradle.kts.proto.jinja 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import com.google.protobuf.gradle.*
  2. val buildProtoDir = File("${buildDir}", "__proto__")
  3. plugins {
  4. id("java-library")
  5. id("com.google.protobuf") version "0.8.19"
  6. {% if targets|selectattr('publish') -%}
  7. `maven-publish`
  8. `signing`
  9. {% endif -%}
  10. }
  11. {% if targets|selectattr('publish') -%}
  12. group = "{{ targets[0].publish_group }}"
  13. version = project.properties["version"]
  14. {% endif -%}
  15. repositories {
  16. mavenCentral()
  17. }
  18. java {
  19. withSourcesJar()
  20. withJavadocJar()
  21. }
  22. dependencies {
  23. {% for library in targets[0].consumer_classpath -%}
  24. api({{ library }})
  25. {% endfor -%}
  26. {% if targets[0].proto_namespace is defined -%}
  27. protobuf(files(File(buildProtoDir, "{{ targets[0].proto_namespace }}")))
  28. {% else -%}
  29. protobuf(files(buildProtoDir))
  30. {% endif -%}
  31. }
  32. {% if targets[0].proto_grpc is defined -%}
  33. protobuf {
  34. plugins {
  35. id("grpc") {
  36. artifact = "io.grpc:protoc-gen-grpc-java:1.45.0"
  37. }
  38. }
  39. generateProtoTasks {
  40. ofSourceSet("main").forEach {
  41. it.plugins {
  42. id("grpc")
  43. }
  44. }
  45. }
  46. }
  47. {% endif -%}
  48. val prepareProto = tasks.register<Copy>("prepareProto") {
  49. from(rootDir) {
  50. {% for proto in targets[0].proto_files -%}
  51. include("{{ proto }}")
  52. {% endfor -%}
  53. }
  54. into(buildProtoDir)
  55. }
  56. afterEvaluate {
  57. tasks.getByName("extractProto").dependsOn(prepareProto)
  58. }
  59. {% if targets|selectattr('publish') -%}
  60. {% include 'publish.gradle.kts' -%}
  61. {% endif -%}