build.gradle.kts.proto.jinja 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. {% set classpath = library.classpath -%}
  26. {% if classpath|replace('"','') == classpath -%}
  27. {% set classpath = '"' + classpath + '"' -%}
  28. {% endif %}
  29. api({{ classpath }})
  30. {%- endfor %}
  31. {% if target.proto_namespace %}
  32. protobuf(files(File(buildProtoDir, "{{ target.proto_namespace }}")))
  33. {%- else %}
  34. protobuf(files(buildProtoDir))
  35. {%- endif %}
  36. }
  37. protobuf {
  38. protoc {
  39. // Download from repositories
  40. artifact = "com.google.protobuf:protoc:
  41. {%- if target.proto_compiler_version -%}
  42. {{ target.proto_compiler_version }}
  43. {%- else -%}
  44. 3.22.5
  45. {%- endif -%}
  46. "
  47. }
  48. {% if target.proto_grpc -%}
  49. plugins {
  50. id("grpc") {
  51. artifact = "io.grpc:protoc-gen-grpc-java:1.45.0"
  52. }
  53. }
  54. generateProtoTasks {
  55. ofSourceSet("main").forEach {
  56. it.plugins {
  57. id("grpc")
  58. }
  59. }
  60. }
  61. {%- endif %}
  62. }
  63. val prepareProto = tasks.register<Copy>("prepareProto") {
  64. from(rootDir) {
  65. {% for proto in target.proto_files -%}
  66. include("{{ proto }}")
  67. {% endfor -%}
  68. }
  69. into(buildProtoDir)
  70. }
  71. afterEvaluate {
  72. tasks.getByName("extractProto").dependsOn(prepareProto)
  73. }
  74. {% if publish -%}
  75. {% include 'publish.gradle.kts' -%}
  76. {% endif -%}