build.gradle.kts.proto.jinja 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 = {% if target.publish_version -%}"{{ target.publish_version }}"{%- else -%}project.properties["version"]{%- endif %}
  15. {%- endif %}
  16. val bucketUsername: String by project
  17. val bucketPassword: String by project
  18. repositories {
  19. repositories {
  20. maven {
  21. url = uri("https://bucket.yandex-team.ru/v1/maven/central")
  22. credentials {
  23. username = "$bucketUsername"
  24. password = "$bucketPassword"
  25. }
  26. }
  27. }
  28. }
  29. sourceSets {
  30. main {
  31. java.srcDir("build/generated/source/proto")
  32. }
  33. }
  34. val project_root="{%- if exportRoot.startswith(arcadiaRoot + '/') -%}{{ arcadiaRoot }}{%- else -%}{{ exportRoot }}{%- endif -%}"
  35. java {
  36. withSourcesJar()
  37. withJavadocJar()
  38. }
  39. configurations.api {
  40. isTransitive = false
  41. }
  42. configurations.implementation {
  43. isTransitive = false
  44. }
  45. configurations.testImplementation {
  46. isTransitive = false
  47. }
  48. {%- if target.jar_source_set is defined -%}
  49. {%- for source_set in target.jar_source_set -%}
  50. {%- set srcdir_glob = split(source_set, ':') -%}
  51. sourceSets.main.java.srcDirs += "{{ srcdir_glob[0] }}"
  52. {% endfor -%}
  53. {%- endif -%}
  54. dependencies {
  55. {%- for library in target.consumer if library.classpath -%}
  56. {%- if library.prebuilt and library.jar and (library.type != "contrib" or target.handler.build_contribs) %}
  57. implementation(files("$project_root/{{ library.jar }}"))
  58. {%- else -%}
  59. {%- if library.type != "contrib" %}
  60. implementation
  61. {%- else %}
  62. api
  63. {%- endif -%}({{ library.classpath }})
  64. {%- if library.excludes.consumer is defined %} {
  65. {% for exclude in library.excludes.consumer -%}
  66. {% set classpath = exclude.classpath|replace('"','') -%}
  67. {% set classpath_parts = split(classpath, ':') -%}
  68. exclude(group = "{{ classpath_parts[0] }}", module = "{{ classpath_parts[1] }}")
  69. {% endfor -%}
  70. }
  71. {%- endif -%}
  72. {%- endif -%}
  73. {%- endfor %}
  74. {% if target.proto_namespace -%}
  75. protobuf(files(File(buildProtoDir, "{{ target.proto_namespace }}")))
  76. {% else -%}
  77. protobuf(files(buildProtoDir))
  78. {% endif -%}
  79. }
  80. protobuf {
  81. protoc {
  82. // Download from repositories
  83. artifact = "com.google.protobuf:protoc:{%- if target.proto_compiler_version -%}{{ target.proto_compiler_version }}{%- else -%}3.22.5{%- endif -%}"
  84. }
  85. {% if target.proto_grpc is defined -%}
  86. plugins {
  87. id("grpc") {
  88. artifact = "io.grpc:protoc-gen-grpc-java:{%- if target.proto_grpc_version -%}{{ target.proto_grpc_version }}{%- else -%}1.45.0{%- endif -%}"
  89. }
  90. }
  91. generateProtoTasks {
  92. all().forEach {
  93. it.plugins {
  94. id("grpc")
  95. }
  96. }
  97. }
  98. {%- endif %}
  99. }
  100. val prepareProto = tasks.register<Copy>("prepareProto") {
  101. from(rootDir) {
  102. {%- for proto in target.proto_files %}
  103. include("{{ proto }}")
  104. {%- endfor %}
  105. {# Mining proto-deps sources directories #}
  106. {%- for library in target.consumer if library.prebuilt -%}
  107. {%- if library.type == "library" %}
  108. {%- set proto_rep = library.classpath|replace('project(":','') %}
  109. {%- set proto_rep = proto_rep|replace('")','') %}
  110. {%- set proto_rep = proto_rep|replace(':','/') %}
  111. {%- set proto = proto_rep + '/**' %}
  112. include("{{ proto }}")
  113. {%- endif -%}
  114. {%- endfor %}
  115. }
  116. into(buildProtoDir)
  117. }
  118. afterEvaluate {
  119. tasks.getByName("extractProto").dependsOn(prepareProto)
  120. }
  121. {%- include "[generator]/debug.jinja" ignore missing -%}