build.gradle.kts.proto.jinja 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 export_root.startswith(arcadia_root + '/') -%}{{ arcadia_root }}{%- else -%}{{ export_root }}{%- 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. {%- set classpath = library.classpath -%}
  60. {%- if classpath|replace('"','') == classpath -%}
  61. {%- set classpath = '"' + classpath + '"' -%}
  62. {%- endif %}
  63. {%- if library.type != "contrib" %}
  64. implementation
  65. {%- else %}
  66. api
  67. {%- endif -%}({{ classpath }})
  68. {%- if library.excludes.consumer is defined %} {
  69. {% for exclude in library.excludes.consumer -%}
  70. {% set classpath = exclude.classpath|replace('"','') -%}
  71. {% set classpath_parts = split(classpath, ':') -%}
  72. exclude(group = "{{ classpath_parts[0] }}", module = "{{ classpath_parts[1] }}")
  73. {% endfor -%}
  74. }
  75. {%- endif -%}
  76. {%- endif -%}
  77. {%- endfor %}
  78. {% if target.proto_namespace -%}
  79. protobuf(files(File(buildProtoDir, "{{ target.proto_namespace }}")))
  80. {% else -%}
  81. protobuf(files(buildProtoDir))
  82. {% endif -%}
  83. }
  84. protobuf {
  85. protoc {
  86. // Download from repositories
  87. artifact = "com.google.protobuf:protoc:{%- if target.proto_compiler_version -%}{{ target.proto_compiler_version }}{%- else -%}3.22.5{%- endif -%}"
  88. }
  89. {% if target.proto_grpc is defined -%}
  90. plugins {
  91. id("grpc") {
  92. artifact = "io.grpc:protoc-gen-grpc-java:{%- if target.proto_grpc_version -%}{{ target.proto_grpc_version }}{%- else -%}1.45.0{%- endif -%}"
  93. }
  94. }
  95. generateProtoTasks {
  96. all().forEach {
  97. it.plugins {
  98. id("grpc")
  99. }
  100. }
  101. }
  102. {%- endif %}
  103. }
  104. val prepareProto = tasks.register<Copy>("prepareProto") {
  105. from(rootDir) {
  106. {%- for proto in target.proto_files %}
  107. include("{{ proto }}")
  108. {%- endfor %}
  109. {# Mining proto-deps sources directories #}
  110. {%- for library in target.consumer if library.prebuilt -%}
  111. {%- if library.type == "library" %}
  112. {%- set proto_rep = library.classpath|replace('project(":','') %}
  113. {%- set proto_rep = proto_rep|replace('")','') %}
  114. {%- set proto_rep = proto_rep|replace(':','/') %}
  115. {%- set proto = proto_rep + '/**' %}
  116. include("{{ proto }}")
  117. {%- endif -%}
  118. {%- endfor %}
  119. }
  120. into(buildProtoDir)
  121. }
  122. afterEvaluate {
  123. tasks.getByName("extractProto").dependsOn(prepareProto)
  124. }
  125. {# To avoid problems when build project with proto #}
  126. tasks.named("sourcesJar").configure {
  127. dependsOn("generateProto")
  128. }
  129. {# To disable redundant javadoc (it may fail the build) #}
  130. tasks.withType<Javadoc>().configureEach {
  131. isEnabled = false
  132. }
  133. {%- include "[generator]/debug.jinja" ignore missing -%}