build.gradle.kts.proto.jinja 1.6 KB

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