{%- set mainClass = target.app_main_class -%} {%- set publish = target.publish -%} {%- set with_kotlin = target.with_kotlin -%} {%- set kotlin_version = target.kotlin_version -%} {%- set hasJunit5Test = extra_targets|selectattr('junit5_test') -%} {%- set errorprone_plugin_version = "4.0.0" -%} plugins { {# some plugins configuration #} {%- for library in target.consumer if library.classpath -%} {# error prone plugin configuration #} {%- if library.prebuilt and library.jar and (library.type != "contrib" or build_contribs) and "contrib/java/com/google/errorprone/error_prone_annotations/" in library.jar -%} id("net.ltgt.errorprone") version "{{ errorprone_plugin_version }}" {%- endif -%} {%- endfor -%} {# lombok configuration #} {%- if "lombok.launch.AnnotationProcessorHider$AnnotationProcessor" in target.annotation_processors %} id("io.freefair.lombok") version "8.6" {%- endif -%} {%- if mainClass %} `application` {%- else %} `java-library` {%- endif %} {%- if publish %} `maven-publish` `signing` {%- endif -%} {%- if with_kotlin and kotlin_version %} kotlin("jvm") version "{{ kotlin_version }}" {%- if target.with_kotlinc_plugin_allopen %} kotlin("plugin.allopen") version "{{ kotlin_version }}" {% endif -%} {%- if target.with_kotlinc_plugin_lombok %} kotlin("plugin.lombok") version "{{ kotlin_version }}" {% endif -%} {%- if target.with_kotlinc_plugin_noarg %} kotlin("plugin.noarg") version "{{ kotlin_version }}" {% endif -%} {%- if target.with_kotlinc_plugin_serialization %} kotlin("plugin.serialization") version "{{ kotlin_version }}" {% endif -%} {%- endif %} } {# language level #} {%- if target.required_jdk != "" %} java { toolchain { languageVersion = JavaLanguageVersion.of("{{ target.required_jdk }}") } } {% endif -%} {%- if target.with_kotlinc_plugin_allopen %} allOpen { annotation("org.springframework.stereotype.Component") } {% endif -%} {%- if with_kotlin %} kotlin { jvmToolchain({%- if target.required_jdk -%}{{ target.required_jdk }}{%- else -%}17{%- endif -%}) } {% endif -%} {%- if publish %} group = "{{ target.publish_group }}" version = {% if target.publish_version and target.publish_version != "no" -%}"{{ target.publish_version }}"{%- else -%}project.properties["version"]!!{%- endif %} {% endif %} {% if target.enable_preview %} tasks.withType { options.compilerArgs.add("--enable-preview") options.compilerArgs.add("-Xlint:preview") options.release.set({%- if target.required_jdk -%}{{ target.required_jdk }}{%- else -%}17{%- endif -%}) } tasks.withType { jvmArgs?.add("--enable-preview") } tasks.withType { jvmArgs?.add("--enable-preview") environment["JAVA_TOOL_OPTIONS"] = "--enable-preview" } tasks.withType { val javadocOptions = options as CoreJavadocOptions javadocOptions.addStringOption("source", "{%- if target.required_jdk -%}{{ target.required_jdk }}{%- else -%}17{%- endif -%}") javadocOptions.addBooleanOption("-enable-preview", true) } {% endif %} {# javac flags #} {%- if (target.javac.flags is defined) and (target.javac.flags|length) %} tasks.withType { {%- for javac_flag in target.javac.flags %} {%- if '-Xep:' in javac_flag %} {% else %} options.compilerArgs.add("{{ javac_flag }}") {%- endif %} {%- endfor %} } {%- endif %} val bucketUsername: String by project val bucketPassword: String by project repositories { repositories { maven { url = uri("https://bucket.yandex-team.ru/v1/maven/central") credentials { username = "$bucketUsername" password = "$bucketPassword" } } } } val project_root="{%- if export_root.startswith(arcadia_root + '/') -%}{{ arcadia_root }}{%- else -%}{{ export_root }}/.hic_sunt_dracones{%- endif -%}" {% if mainClass -%} application { mainClass.set("{{ mainClass }}") } {% endif -%} java { withSourcesJar() withJavadocJar() } configurations.api { isTransitive = false } configurations.implementation { isTransitive = false } configurations.testImplementation { isTransitive = false } {% if has_test -%} val testsJar by tasks.registering(Jar::class) { dependsOn(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME) archiveClassifier.set("tests") from(sourceSets["test"].output) } artifacts.add(configurations.create("testArtifacts").name, testsJar) tasks.test { testLogging { showStandardStreams = true events("passed", "skipped", "failed") } } {% endif -%} {%- if target.jar_source_set is defined -%} {%- for source_set in target.jar_source_set -%} {%- set srcdir_glob = split(source_set, ':') -%} sourceSets.main.java.srcDirs += "{{ srcdir_glob[0] }}" {% endfor -%} {%- endif -%} {% for extra_target in extra_targets -%} {%- if extra_target.jar_source_set is defined -%} {%- for source_set in extra_target.jar_source_set -%} {%- set srcdir_glob = split(source_set, ':') -%} sourceSets.main.java.srcDirs += "{{ srcdir_glob[0] }}" {% endfor -%} {%- endif -%} {%- endfor -%} sourceSets { val test by getting { java.srcDir("ut/java") resources.srcDir("ut/resources") java.srcDir("src/test-integration/java") resources.srcDir("src/test-integration/resources") java.srcDir("src/testFixtures/java") resources.srcDir("src/testFixtures/resources") java.srcDir("src/intTest/java") resources.srcDir("src/intTest/resources") } } dependencies { {%- for library in target.consumer if library.classpath -%} {# error prone plugin configuration #} {%- if library.prebuilt and library.jar and (library.type != "contrib" or build_contribs) and "contrib/java/com/google/errorprone/error_prone_annotations" in library.jar -%} {% set errorprone_version = library.jar -%} {% set errorprone_parts = errorprone_version|replace("contrib/java/com/google/errorprone/error_prone_annotations/") -%} {% set errorprone_parts = split(errorprone_parts, '/') -%} errorprone("com.google.errorprone:error_prone_core:{{ errorprone_parts[0] }}") {%- endif -%} {%- if library.prebuilt and library.jar and (library.type != "contrib" or build_contribs) %} implementation(files("$project_root/{{ library.jar }}")) {%- else -%} {%- set classpath = library.classpath -%} {%- if classpath|replace('"','') == classpath -%} {%- set classpath = '"' + classpath + '"' -%} {%- endif -%} {%- if library.type != "contrib" %} {%- if library.testdep %} implementation(project(path = ":{{ library.testdep | replace("/", ":") }}", configuration = "testArtifacts")) {%- else %} implementation({{ classpath }}) {%- endif -%} {%- else %} api({{ classpath }}) {%- endif -%} {%- if library.excludes.consumer is defined %} { {% for exclude in library.excludes.consumer if exclude.classpath -%} {% set classpath = exclude.classpath|replace('"','') -%} {% set classpath_parts = split(classpath, ':') -%} exclude(group = "{{ classpath_parts[0] }}", module = "{{ classpath_parts[1] }}") {% endfor -%} } {%- endif -%} {%- endif -%} {%- endfor -%} {%- for extra_target in extra_targets -%} {%- for library in extra_target.consumer if library.classpath -%} {%- if library.prebuilt and library.jar and (library.type != "contrib" or build_contribs) %} testImplementation(files("$project_root/{{ library.jar }}")) {%- else -%} {%- set classpath = library.classpath -%} {%- if classpath|replace('"','') == classpath -%} {%- set classpath = '"' + classpath + '"' -%} {%- endif %} {%- if library.type != "contrib" and library.testdep %} testImplementation(project(path = ":{{ library.testdep | replace("/", ":") }}", configuration = "testArtifacts")) {%- else %} testImplementation({{ classpath }}) {%- endif -%} {%- if library.excludes.consumer is defined %} { {% for exclude in library.excludes.consumer if exclude.classpath -%} {% set classpath = exclude.classpath|replace('"','') -%} {% set classpath_parts = split(classpath, ':') -%} exclude(group = "{{ classpath_parts[0] }}", module = "{{ classpath_parts[1] }}") {% endfor -%} } {%- endif -%} {%- endif -%} {%- endfor -%} {%- endfor %} } {% if hasJunit5Test -%} tasks.named("test") { useJUnitPlatform() } {% endif -%} {# run_java_program #} {# {% set runs = targets|selectattr("runs") -%} #} {% set runs = target.runs -%} {% if runs -%} {% for run in runs -%} val runJav{{ loop.index }} = task("runJavaProgram{{ loop.index }}") { group = "build" description = "Code generation by run java program" mainClass.set("{{ run.args[0] }}") {% if run.classpath -%} {% for classpath in run.classpath -%} {% set real_classpath = classpath|replace('@', '') -%} {% set real_classpath = real_classpath|replace('.run.cp', '') -%} {% set real_classpath = real_classpath|replace('.cplst', '') -%} {% set real_classpath = real_classpath|replace(export_root, '') -%} {% set real_gradle_classpath = real_classpath|replace('/', ':') %} val classPath = "{{ real_gradle_classpath }}" val classPathParts = classPath.split(":") classPathParts[classPathParts.size - 2] classpath = files("$project_root{{ real_classpath }}") + project(classPath.replace(":${classPathParts[classPathParts.size - 2]}.jar", "")).configurations.runtimeClasspath.get() {% endfor -%} {% else -%} classpath = sourceSets.main.get().runtimeClasspath {% endif -%} {% set args = run.args -%} {% if args -%} val argsList = mutableListOf( {% for arg in args -%} "{{ arg }}", {% endfor -%} ) argsList.removeAt(0) args = argsList {% endif -%} {% if run.in_dir -%} {% for dir in run.in_dir -%} inputs.files(fileTree("{{ dir }}")) {% endfor -%} {% endif -%} {% if run.in -%} {% for file in run.in -%} inputs.files("{{ file }}") {% endfor -%} {% endif -%} {% if run.out_dir -%} {% for dir in run.out_dir -%} outputs.dir("{{ dir }}") {% endfor -%} {# Не использованы аттрибуты run-cwd="str" run-in_dirs_inputs="list" run-in_noparse="list" run-out_dir="list" run-tool="list" #} {% endif -%} } tasks { build { dependsOn(runJav{{ loop.index }}) } } {% endfor -%} {% endif -%} {% include "extra-tests.gradle.kts" ignore missing %} {% if publish -%} {% include 'publish.gradle.kts' ignore missing -%} {% endif -%} {# To disable redundant javadoc (it may fail the build) #} tasks.withType().configureEach { isEnabled = false } {%- include "[generator]/debug.jinja" ignore missing -%}