build.gradle.kts.proto.jinja 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. protobuf {
  33. protoc {
  34. // Download from repositories
  35. artifact = "com.google.protobuf:protoc:
  36. {%- if targets[0].proto_compiler_version is defined -%}
  37. {{ targets[0].proto_compiler_version }}
  38. {%- else -%}
  39. 3.22.5
  40. {%- endif -%}
  41. "
  42. }
  43. {% if targets[0].proto_grpc is defined -%}
  44. plugins {
  45. id("grpc") {
  46. artifact = "io.grpc:protoc-gen-grpc-java:1.45.0"
  47. }
  48. }
  49. generateProtoTasks {
  50. ofSourceSet("main").forEach {
  51. it.plugins {
  52. id("grpc")
  53. }
  54. }
  55. }
  56. {%- endif %}
  57. }
  58. val prepareProto = tasks.register<Copy>("prepareProto") {
  59. from(rootDir) {
  60. {% for proto in targets[0].proto_files -%}
  61. include("{{ proto }}")
  62. {% endfor -%}
  63. }
  64. into(buildProtoDir)
  65. }
  66. afterEvaluate {
  67. tasks.getByName("extractProto").dependsOn(prepareProto)
  68. }
  69. {% if targets|selectattr('publish') -%}
  70. {% include 'publish.gradle.kts' -%}
  71. {% endif -%}