build.gradle.kts.jinja 7.9 KB

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