build.gradle.kts.proto.jinja 1.7 KB

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