build.gradle.kts.proto.jinja 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. {%- set publish = targets|selectattr('publish') -%}
  2. {%- set target0 = targets[0] -%}
  3. import com.google.protobuf.gradle.*
  4. val buildProtoDir = File("${buildDir}", "__proto__")
  5. plugins {
  6. id("java-library")
  7. id("com.google.protobuf") version "0.8.19"
  8. {%- if publish %}
  9. `maven-publish`
  10. `signing`
  11. {%- endif -%}
  12. }
  13. {%- if publish %}
  14. group = "{{ target0.publish_group }}"
  15. version = {% if target0.publish_version -%}"{{ target0.publish_version }}"{%- else -%}project.properties["version"]{%- endif %}
  16. {%- endif %}
  17. repositories {
  18. mavenCentral()
  19. }
  20. java {
  21. withSourcesJar()
  22. withJavadocJar()
  23. }
  24. configurations.api {
  25. isTransitive = false
  26. }
  27. configurations.implementation {
  28. isTransitive = false
  29. }
  30. configurations.testImplementation {
  31. isTransitive = false
  32. }
  33. {% for target in targets -%}
  34. {%- if target.jar_source_set is defined -%}
  35. {%- for source_set in target.jar_source_set -%}
  36. {%- set srcdir_glob = split(source_set, ':') -%}
  37. sourceSets.main.java.srcDirs += "{{ srcdir_glob[0] }}"
  38. {% endfor -%}
  39. {%- endif -%}
  40. {%- endfor -%}
  41. dependencies {
  42. {%- for target in targets -%}
  43. {%- for library in target.consumer if library.classpath -%}
  44. {%- if library.prebuilt and library.jar and (library.type != "contrib" or target.handler.build_contribs) -%}
  45. {%- if target.isTest %}
  46. testImplementation
  47. {%- else %}
  48. implementation
  49. {%- endif -%}(files("$project_root/{{ library.jar }}"))
  50. {%- else -%}
  51. {%- if target.isTest %}
  52. testImplementation
  53. {%- elif library.type != "contrib" %}
  54. implementation
  55. {%- else %}
  56. api
  57. {%- endif -%}({{ library.classpath }})
  58. {%- if library.excludes.consumer is defined %} {
  59. {% for exclude in library.excludes.consumer -%}
  60. {% set classpath = exclude.classpath|replace('"','') -%}
  61. {% set classpath_parts = split(classpath, ':') -%}
  62. exclude(group = "{{ classpath_parts[0] }}", module = "{{ classpath_parts[1] }}")
  63. {% endfor -%}
  64. }
  65. {%- endif -%}
  66. {%- endif -%}
  67. {%- endfor -%}
  68. {%- endfor %}
  69. {% if target0.proto_namespace is defined -%}
  70. protobuf(files(File(buildProtoDir, "{{ target0.proto_namespace }}")))
  71. {% else -%}
  72. protobuf(files(buildProtoDir))
  73. {% endif -%}
  74. }
  75. protobuf {
  76. protoc {
  77. // Download from repositories
  78. artifact = "com.google.protobuf:protoc:{%- if target0.proto_compiler_version is defined -%}{{ target0.proto_compiler_version }}{%- else -%}3.22.5{%- endif -%}"
  79. }
  80. {% if target0.proto_grpc is defined -%}
  81. plugins {
  82. id("grpc") {
  83. artifact = "io.grpc:protoc-gen-grpc-java:{%- if target0.proto_grpc_version -%}{{ target0.proto_grpc_version }}{%- else -%}1.45.0{%- endif -%}"
  84. }
  85. }
  86. generateProtoTasks {
  87. ofSourceSet("main").forEach {
  88. it.plugins {
  89. id("grpc")
  90. }
  91. }
  92. }
  93. {%- endif %}
  94. }
  95. val prepareProto = tasks.register<Copy>("prepareProto") {
  96. from(rootDir) {
  97. {%- for proto in target0.proto_files %}
  98. include("{{ proto }}")
  99. {%- endfor %}
  100. }
  101. into(buildProtoDir)
  102. }
  103. afterEvaluate {
  104. tasks.getByName("extractProto").dependsOn(prepareProto)
  105. }
  106. {{ dump }}