build.gradle.kts.proto.jinja 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. {%- set publish = target.publish -%}
  2. import com.google.protobuf.gradle.*
  3. val baseBuildDir = "{{ export_root }}/gradle.build/"
  4. buildDir = file(baseBuildDir + project.path.replaceFirst(":", "/").replace(":", "."))
  5. subprojects {
  6. buildDir = file(baseBuildDir + project.path.replaceFirst(":", "/").replace(":", "."))
  7. }
  8. val buildProtoDir = File("${buildDir}", "__proto__")
  9. plugins {
  10. id("java-library")
  11. id("com.google.protobuf") version "0.8.19"
  12. {%- if publish %}
  13. `maven-publish`
  14. `signing`
  15. {%- endif %}
  16. }
  17. {%- if publish %}
  18. group = "{{ target.publish_group }}"
  19. version = {% if target.publish_version -%}"{{ target.publish_version }}"{%- else -%}project.properties["version"]{%- endif %}
  20. {%- endif %}
  21. val bucketUsername: String by project
  22. val bucketPassword: String by project
  23. repositories {
  24. repositories {
  25. maven {
  26. url = uri("https://bucket.yandex-team.ru/v1/maven/central")
  27. credentials {
  28. username = "$bucketUsername"
  29. password = "$bucketPassword"
  30. }
  31. }
  32. }
  33. }
  34. sourceSets {
  35. main {
  36. java.srcDir("build/generated/source/proto")
  37. }
  38. }
  39. val project_root = "{{ arcadia_root }}"
  40. java {
  41. withSourcesJar()
  42. withJavadocJar()
  43. }
  44. configurations.api {
  45. isTransitive = false
  46. }
  47. configurations.implementation {
  48. isTransitive = false
  49. }
  50. configurations.testImplementation {
  51. isTransitive = false
  52. }
  53. {%- if target.jar_source_set is defined -%}
  54. {%- for source_set in target.jar_source_set -%}
  55. {%- set srcdir_glob = split(source_set, ':') %}
  56. sourceSets.main.java.srcDirs += "{{ srcdir_glob[0] }}"
  57. {% endfor -%}
  58. {%- endif %}
  59. dependencies {
  60. {%- for library in target.consumer if library.classpath -%}
  61. {%- if library.prebuilt and library.jar and (library.type != "contrib" or target.handler.build_contribs) %}
  62. implementation(files("$project_root/{{ library.jar }}"))
  63. {%- else -%}
  64. {%- set classpath = library.classpath -%}
  65. {%- if classpath|replace('"','') == classpath -%}
  66. {%- set classpath = '"' + classpath + '"' -%}
  67. {%- endif %}
  68. {%- if library.type != "contrib" %}
  69. implementation
  70. {%- else %}
  71. api
  72. {%- endif -%}({{ classpath }})
  73. {%- if library.excludes.consumer is defined %} {
  74. {% for exclude in library.excludes.consumer -%}
  75. {% set classpath = exclude.classpath|replace('"','') -%}
  76. {% set classpath_parts = split(classpath, ':') -%}
  77. exclude(group = "{{ classpath_parts[0] }}", module = "{{ classpath_parts[1] }}")
  78. {% endfor -%}
  79. }
  80. {%- endif -%}
  81. {%- endif -%}
  82. {%- endfor %}
  83. {% if target.proto_namespace -%}
  84. protobuf(files(File(buildProtoDir, "{{ target.proto_namespace }}")))
  85. {% else -%}
  86. protobuf(files(buildProtoDir))
  87. {% endif -%}
  88. }
  89. protobuf {
  90. protoc {
  91. // Download from repositories
  92. artifact = "com.google.protobuf:protoc:{%- if target.proto_compiler_version -%}{{ target.proto_compiler_version }}{%- else -%}3.22.5{%- endif -%}"
  93. }
  94. {% if target.proto_grpc is defined -%}
  95. plugins {
  96. id("grpc") {
  97. artifact = "io.grpc:protoc-gen-grpc-java:{%- if target.proto_grpc_version -%}{{ target.proto_grpc_version }}{%- else -%}1.45.0{%- endif -%}"
  98. }
  99. }
  100. generateProtoTasks {
  101. all().forEach {
  102. it.plugins {
  103. id("grpc")
  104. }
  105. }
  106. }
  107. {%- endif %}
  108. }
  109. val prepareProto = tasks.register<Copy>("prepareProto") {
  110. from(rootDir) {
  111. {%- for proto in target.proto_files %}
  112. include("{{ proto }}")
  113. {%- endfor %}
  114. {# Mining proto-deps sources directories #}
  115. {%- for library in target.consumer if library.prebuilt -%}
  116. {%- if library.type == "library" %}
  117. {%- set proto_rep = library.classpath|replace('project(":','') %}
  118. {%- set proto_rep = proto_rep|replace('")','') %}
  119. {%- set proto_rep = proto_rep|replace(':','/') %}
  120. {%- set proto = proto_rep + '/**' %}
  121. include("{{ proto }}")
  122. {%- endif -%}
  123. {%- endfor %}
  124. }
  125. into(buildProtoDir)
  126. }
  127. afterEvaluate {
  128. tasks.getByName("extractProto").dependsOn(prepareProto)
  129. }
  130. {# To avoid problems when build project with proto #}
  131. tasks.named("sourcesJar").configure {
  132. dependsOn("generateProto")
  133. }
  134. {# To disable redundant javadoc (it may fail the build) #}
  135. tasks.withType<Javadoc>().configureEach {
  136. isEnabled = false
  137. }
  138. {%- include "[generator]/debug.jinja" ignore missing -%}