build.gradle.kts.jinja 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. {%- set mainClass = target.app_main_class -%}
  2. {%- set publish = target.publish -%}
  3. {%- set with_kotlin = target.with_kotlin -%}
  4. {%- set kotlin_version = target.kotlin_version -%}
  5. {%- set hasJunit5Test = extra_targets|selectattr('junit5_test') -%}
  6. plugins {
  7. {%- if "lombok.launch.AnnotationProcessorHider$AnnotationProcessor" in target.annotation_processors %}
  8. id("io.freefair.lombok") version "8.6"
  9. {%- endif -%}
  10. {%- if mainClass %}
  11. `application`
  12. {%- else %}
  13. `java-library`
  14. {%- endif %}
  15. {%- if publish %}
  16. `maven-publish`
  17. `signing`
  18. {%- endif -%}
  19. {%- if with_kotlin and kotlin_version %}
  20. kotlin("jvm") version "{{ kotlin_version }}"
  21. {%- if target.with_kotlinc_plugin_allopen %}
  22. kotlin("plugin.allopen") version "{{ kotlin_version }}"
  23. {% endif -%}
  24. {%- if target.with_kotlinc_plugin_lombok %}
  25. kotlin("plugin.lombok") version "{{ kotlin_version }}"
  26. {% endif -%}
  27. {%- if target.with_kotlinc_plugin_noarg %}
  28. kotlin("plugin.noarg") version "{{ kotlin_version }}"
  29. {% endif -%}
  30. {%- if target.with_kotlinc_plugin_serialization %}
  31. kotlin("plugin.serialization") version "{{ kotlin_version }}"
  32. {% endif -%}
  33. {%- endif %}
  34. }
  35. {%- if target.with_kotlinc_plugin_allopen %}
  36. allOpen {
  37. annotation("org.springframework.stereotype.Component")
  38. }
  39. {% endif -%}
  40. {%- if with_kotlin %}
  41. kotlin {
  42. jvmToolchain({%- if target.required_jdk -%}{{ target.required_jdk }}{%- else -%}17{%- endif -%})
  43. }
  44. {% endif -%}
  45. {%- if publish %}
  46. group = "{{ target.publish_group }}"
  47. version = {% if target.publish_version and target.publish_version != "no" -%}"{{ target.publish_version }}"{%- else -%}project.properties["version"]!!{%- endif %}
  48. {% endif %}
  49. {% if target.enable_preview %}
  50. tasks.withType<JavaCompile> {
  51. options.compilerArgs.add("--enable-preview")
  52. options.compilerArgs.add("-Xlint:preview")
  53. options.release.set({%- if target.required_jdk -%}{{ target.required_jdk }}{%- else -%}17{%- endif -%})
  54. }
  55. tasks.withType<JavaExec> {
  56. jvmArgs?.add("--enable-preview")
  57. }
  58. tasks.withType<Test> {
  59. jvmArgs?.add("--enable-preview")
  60. environment["JAVA_TOOL_OPTIONS"] = "--enable-preview"
  61. }
  62. tasks.withType<Javadoc> {
  63. val javadocOptions = options as CoreJavadocOptions
  64. javadocOptions.addStringOption("source", "{%- if target.required_jdk -%}{{ target.required_jdk }}{%- else -%}17{%- endif -%}")
  65. javadocOptions.addBooleanOption("-enable-preview", true)
  66. }
  67. {% endif %}
  68. val bucketUsername: String by project
  69. val bucketPassword: String by project
  70. repositories {
  71. repositories {
  72. maven {
  73. url = uri("https://bucket.yandex-team.ru/v1/maven/central")
  74. credentials {
  75. username = "$bucketUsername"
  76. password = "$bucketPassword"
  77. }
  78. }
  79. }
  80. }
  81. val project_root="{%- if exportRoot.startswith(arcadiaRoot + '/') -%}{{ arcadiaRoot }}{%- else -%}{{ exportRoot }}{%- endif -%}"
  82. {% if mainClass -%}
  83. application {
  84. mainClass.set("{{ mainClass }}")
  85. }
  86. {% endif -%}
  87. java {
  88. withSourcesJar()
  89. withJavadocJar()
  90. }
  91. configurations.api {
  92. isTransitive = false
  93. }
  94. configurations.implementation {
  95. isTransitive = false
  96. }
  97. configurations.testImplementation {
  98. isTransitive = false
  99. }
  100. {% if hasTest -%}
  101. val testsJar by tasks.registering(Jar::class) {
  102. dependsOn(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME)
  103. archiveClassifier.set("tests")
  104. from(sourceSets["test"].output)
  105. }
  106. artifacts.add(configurations.create("testArtifacts").name, testsJar)
  107. tasks.test {
  108. testLogging {
  109. showStandardStreams = true
  110. events("passed", "skipped", "failed")
  111. }
  112. }
  113. {% endif -%}
  114. {%- if target.jar_source_set is defined -%}
  115. {%- for source_set in target.jar_source_set -%}
  116. {%- set srcdir_glob = split(source_set, ':') -%}
  117. sourceSets.main.java.srcDirs += "{{ srcdir_glob[0] }}"
  118. {% endfor -%}
  119. {%- endif -%}
  120. {% for extra_target in extra_targets -%}
  121. {%- if extra_target.jar_source_set is defined -%}
  122. {%- for source_set in extra_target.jar_source_set -%}
  123. {%- set srcdir_glob = split(source_set, ':') -%}
  124. sourceSets.main.java.srcDirs += "{{ srcdir_glob[0] }}"
  125. {% endfor -%}
  126. {%- endif -%}
  127. {%- endfor -%}
  128. sourceSets {
  129. val test by getting {
  130. java.srcDir("ut/java")
  131. resources.srcDir("ut/resources")
  132. java.srcDir("src/test-integration/java")
  133. resources.srcDir("src/test-integration/resources")
  134. java.srcDir("src/testFixtures/java")
  135. resources.srcDir("src/testFixtures/resources")
  136. java.srcDir("src/intTest/java")
  137. resources.srcDir("src/intTest/resources")
  138. }
  139. }
  140. dependencies {
  141. {%- for library in target.consumer if library.classpath -%}
  142. {%- if library.prebuilt and library.jar and (library.type != "contrib" or build_contribs) %}
  143. implementation(files("$project_root/{{ library.jar }}"))
  144. {%- else -%}
  145. {%- if library.type != "contrib" %}
  146. {%- if library.testdep %}
  147. implementation(project(path = ":{{ library.testdep | replace("/", ":") }}", configuration = "testArtifacts"))
  148. {%- else %}
  149. implementation({{ library.classpath }})
  150. {%- endif -%}
  151. {%- else %}
  152. api({{ library.classpath }})
  153. {%- endif -%}
  154. {%- if library.excludes.consumer is defined %} {
  155. {% for exclude in library.excludes.consumer if exclude.classpath -%}
  156. {% set classpath = exclude.classpath|replace('"','') -%}
  157. {% set classpath_parts = split(classpath, ':') -%}
  158. exclude(group = "{{ classpath_parts[0] }}", module = "{{ classpath_parts[1] }}")
  159. {% endfor -%}
  160. }
  161. {%- endif -%}
  162. {%- endif -%}
  163. {%- endfor -%}
  164. {%- for extra_target in extra_targets -%}
  165. {%- for library in extra_target.consumer if library.classpath -%}
  166. {%- if library.prebuilt and library.jar and (library.type != "contrib" or build_contribs) %}
  167. testImplementation(files("$project_root/{{ library.jar }}"))
  168. {%- else -%}
  169. {%- if library.type != "contrib" and library.testdep %}
  170. testImplementation(project(path = ":{{ library.testdep | replace("/", ":") }}", configuration = "testArtifacts"))
  171. {%- else %}
  172. testImplementation({{ library.classpath }})
  173. {%- endif -%}
  174. {%- if library.excludes.consumer is defined %} {
  175. {% for exclude in library.excludes.consumer if exclude.classpath -%}
  176. {% set classpath = exclude.classpath|replace('"','') -%}
  177. {% set classpath_parts = split(classpath, ':') -%}
  178. exclude(group = "{{ classpath_parts[0] }}", module = "{{ classpath_parts[1] }}")
  179. {% endfor -%}
  180. }
  181. {%- endif -%}
  182. {%- endif -%}
  183. {%- endfor -%}
  184. {%- endfor %}
  185. }
  186. {% if hasJunit5Test -%}
  187. tasks.named<Test>("test") {
  188. useJUnitPlatform()
  189. }
  190. {% endif -%}
  191. {% set runs = targets|selectattr("runs") -%}
  192. {% if runs -%}
  193. {% for run in runs -%}
  194. tasks.build.dependsOn(
  195. task<JavaExec>("runJavaProgram") {
  196. group = "build"
  197. description = "Code generation by rub java program"
  198. mainClass.set(mainClass)
  199. {% if run.classpath -%}
  200. classpath = "{{ run.classpath }}"
  201. {% else -%}
  202. classpath = sourceSets.main.get().runtimeClasspath
  203. {% endif -%}
  204. {% if run.args -%}
  205. {# for arg in run.args #}
  206. args = "{{ run.args }}"
  207. {% endif -%}
  208. {% if run.in_dir -%}
  209. {% for dir in run.in_dir -%}
  210. inputs.files(fileTree("{{ dir }}"))
  211. {% endfor -%}
  212. {% endif -%}
  213. {% if run.in -%}
  214. {% for file in run.in -%}
  215. inputs.files("{{ file }}")
  216. {% endfor -%}
  217. {% endif -%}
  218. {% if run.out_dir -%}
  219. {% for dir in run.out_dir -%}
  220. outputs.dir("{{ dir }}")
  221. {% endfor -%}
  222. {#
  223. Не использованы аттрибуты
  224. run-cwd="str"
  225. run-in_dirs_inputs="list"
  226. run-in_noparse="list"
  227. run-out_dir="list"
  228. run-tool="list"
  229. #}
  230. {% endif -%}
  231. }
  232. )
  233. {% endfor -%}
  234. {% endif -%}
  235. {% include "extra-tests.gradle.kts" ignore missing %}
  236. {% if publish -%}
  237. {% include 'publish.gradle.kts' ignore missing -%}
  238. {% endif -%}
  239. {# To disable redundant javadoc (it may fail the build) #}
  240. tasks.withType<Javadoc>().configureEach {
  241. isEnabled = false
  242. }
  243. {%- include "[generator]/debug.jinja" ignore missing -%}