build.gradle.kts.jinja 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. {%- set mainClassTargets = targets|selectattr("app_main_class") -%}
  2. {%- set publish = targets|selectattr('publish') -%}
  3. {%- set hasJunit5Test = targets|selectattr('junit5_test') -%}
  4. {%- set target0 = targets[0] -%}
  5. {%- set with_kotlin = target0.with_kotlin -%}
  6. {%- set kotlin_version = target0.kotlin_version -%}
  7. plugins {
  8. {%- if mainClassTargets %}
  9. `application`
  10. {%- else %}
  11. `java-library`
  12. {%- endif %}
  13. {%- if publish %}
  14. `maven-publish`
  15. `signing`
  16. {%- endif -%}
  17. {%- if with_kotlin and kotlin_version %}
  18. kotlin("jvm") version "{{ kotlin_version }}"
  19. {%- if target0.with_kotlinc_plugin_allopen %}
  20. kotlin("plugin.allopen") version "{{ kotlin_version }}"
  21. {% endif -%}
  22. {%- if target0.with_kotlinc_plugin_lombok %}
  23. kotlin("plugin.lombok") version "{{ kotlin_version }}"
  24. {% endif -%}
  25. {%- if target0.with_kotlinc_plugin_noarg %}
  26. kotlin("plugin.noarg") version "{{ kotlin_version }}"
  27. {% endif -%}
  28. {%- if target0.with_kotlinc_plugin_serialization %}
  29. kotlin("plugin.serialization") version "{{ kotlin_version }}"
  30. {% endif -%}
  31. {%- endif %}
  32. }
  33. {%- if target0.with_kotlinc_plugin_allopen %}
  34. allOpen {
  35. annotation("org.springframework.stereotype.Component")
  36. }
  37. {% endif -%}
  38. {%- if with_kotlin %}
  39. kotlin {
  40. jvmToolchain({%- if target0.required_jdk -%}{{ target0.required_jdk }}{%- else -%}17{%- endif -%})
  41. }
  42. {% endif -%}
  43. {%- if publish %}
  44. group = "{{ target0.publish_group }}"
  45. version = {% if target0.publish_version and target0.publish_version != "no" -%}"{{ target0.publish_version }}"{%- else -%}project.properties["version"]{%- endif %}
  46. {% endif %}
  47. repositories {
  48. mavenCentral()
  49. }
  50. val project_root="{%- if exportRoot.startswith(arcadiaRoot + '/') -%}{{ arcadiaRoot }}{%- else -%}{{ exportRoot }}{%- endif -%}"
  51. {% if mainClassTargets -%}
  52. application {
  53. {%- for target in mainClassTargets %}
  54. mainClass.set("{{ target.app_main_class }}")
  55. {% endfor -%}
  56. }
  57. {% endif -%}
  58. java {
  59. withSourcesJar()
  60. withJavadocJar()
  61. }
  62. configurations.api {
  63. isTransitive = false
  64. }
  65. configurations.implementation {
  66. isTransitive = false
  67. }
  68. configurations.testImplementation {
  69. isTransitive = false
  70. }
  71. {% if hasTest -%}
  72. val testsJar by tasks.registering(Jar::class) {
  73. dependsOn(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME)
  74. archiveClassifier.set("tests")
  75. from(sourceSets["test"].output)
  76. }
  77. artifacts.add(configurations.create("testArtifacts").name, testsJar)
  78. tasks.test {
  79. testLogging {
  80. showStandardStreams = true
  81. events("passed", "skipped", "failed")
  82. }
  83. }
  84. {% endif -%}
  85. {% for target in targets -%}
  86. {%- if target.jar_source_set is defined -%}
  87. {%- for source_set in target.jar_source_set -%}
  88. {%- set srcdir_glob = split(source_set, ':') -%}
  89. sourceSets.main.java.srcDirs += "{{ srcdir_glob[0] }}"
  90. {% endfor -%}
  91. {%- endif -%}
  92. {%- endfor -%}
  93. dependencies {
  94. {%- for target in targets -%}
  95. {%- for library in target.consumer if library.classpath -%}
  96. {%- if library.prebuilt and library.jar and (library.type != "contrib" or build_contribs) -%}
  97. {%- if target.isTest %}
  98. testImplementation
  99. {%- else %}
  100. implementation
  101. {%- endif -%}(files("$project_root/{{ library.jar }}"))
  102. {%- else -%}
  103. {%- if target.isTest %}
  104. {%- if library.type != "contrib" and library.test2test %}
  105. testImplementation(project(path = ":{{ library.test2test | replace("/", ":") }}", configuration = "testArtifacts"))
  106. {%- else %}
  107. testImplementation({{ library.classpath }})
  108. {%- endif %}
  109. {%- elif library.type != "contrib" %}
  110. implementation({{ library.classpath }})
  111. {%- else %}
  112. api({{ library.classpath }})
  113. {%- endif -%}
  114. {%- if library.excludes.consumer is defined %} {
  115. {% for exclude in library.excludes.consumer if exclude.classpath -%}
  116. {% set classpath = exclude.classpath|replace('"','') -%}
  117. {% set classpath_parts = split(classpath, ':') -%}
  118. exclude(group = "{{ classpath_parts[0] }}", module = "{{ classpath_parts[1] }}")
  119. {% endfor -%}
  120. }
  121. {%- endif -%}
  122. {%- endif -%}
  123. {%- endfor -%}
  124. {%- endfor %}
  125. }
  126. {% if hasJunit5Test -%}
  127. tasks.named<Test>("test") {
  128. useJUnitPlatform()
  129. }
  130. {% endif -%}
  131. {% set runs = targets|selectattr("runs") -%}
  132. {% if runs -%}
  133. {% for run in runs -%}
  134. tasks.build.dependsOn(
  135. task<JavaExec>("runJavaProgram") {
  136. group = "build"
  137. description = "Code generation by rub java program"
  138. mainClass.set(mainClass)
  139. {% if run.classpath -%}
  140. classpath = "{{ run.classpath }}"
  141. {% else -%}
  142. classpath = sourceSets.main.get().runtimeClasspath
  143. {% endif -%}
  144. {% if run.args -%}
  145. {# for arg in run.args #}
  146. args = "{{ run.args }}"
  147. {% endif -%}
  148. {% if run.in_dir -%}
  149. {% for dir in run.in_dir -%}
  150. inputs.files(fileTree("{{ dir }}"))
  151. {% endfor -%}
  152. {% endif -%}
  153. {% if run.in -%}
  154. {% for file in run.in -%}
  155. inputs.files("{{ file }}")
  156. {% endfor -%}
  157. {% endif -%}
  158. {% if run.out_dir -%}
  159. {% for dir in run.out_dir -%}
  160. outputs.dir("{{ dir }}")
  161. {% endfor -%}
  162. {#
  163. Не использованы аттрибуты
  164. run-cwd="str"
  165. run-in_dirs_inputs="list"
  166. run-in_noparse="list"
  167. run-out_dir="list"
  168. run-tool="list"
  169. #}
  170. {% endif -%}
  171. }
  172. )
  173. {% endfor -%}
  174. {% endif -%}
  175. {% include "extra-tests.gradle.kts" ignore missing %}
  176. {% if publish -%}
  177. {% include 'publish.gradle.kts' ignore missing -%}
  178. {% endif -%}
  179. {{ dump }}