aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordimdim11 <dimdim11@yandex-team.com>2024-12-10 10:32:26 +0300
committerdimdim11 <dimdim11@yandex-team.com>2024-12-10 10:51:26 +0300
commitdc3e62419c27e433c71ecc7918926f79b0d492ac (patch)
treebda52c1dd642b76366a777b70ce81877492b0f7e
parenteebc72eb00185f8053096ff6181ce862516bc68c (diff)
downloadydb-dc3e62419c27e433c71ecc7918926f79b0d492ac.tar.gz
Refactor ide-gradle templates
Refactor ide-gradle templates commit_hash:58147076392cab3f86ba196c01f437e39173e48e
-rw-r--r--build/export_generators/gradle/build.gradle.kts.jinja6
-rw-r--r--build/export_generators/ide-gradle/build.gradle.kts.jinja135
-rw-r--r--build/export_generators/ide-gradle/build.gradle.kts.proto.jinja183
-rw-r--r--build/export_generators/ide-gradle/builddir.jinja1
-rw-r--r--build/export_generators/ide-gradle/configuration.jinja25
-rw-r--r--build/export_generators/ide-gradle/dependencies.jinja1
-rw-r--r--build/export_generators/ide-gradle/errorprone.jinja1
-rw-r--r--build/export_generators/ide-gradle/import.jinja5
-rw-r--r--build/export_generators/ide-gradle/javac_flags.jinja12
-rw-r--r--build/export_generators/ide-gradle/javadoc.jinja4
-rw-r--r--build/export_generators/ide-gradle/plugins.jinja3
-rw-r--r--build/export_generators/ide-gradle/proto_builddir.jinja5
-rw-r--r--build/export_generators/ide-gradle/proto_configuration.jinja19
-rw-r--r--build/export_generators/ide-gradle/proto_dependencies.jinja32
-rw-r--r--build/export_generators/ide-gradle/proto_import.jinja3
-rw-r--r--build/export_generators/ide-gradle/proto_plugins.jinja9
-rw-r--r--build/export_generators/ide-gradle/proto_prepare.jinja32
-rw-r--r--build/export_generators/ide-gradle/proto_source_sets.jinja22
-rw-r--r--build/export_generators/ide-gradle/proto_vars.jinja2
-rw-r--r--build/export_generators/ide-gradle/protobuf.jinja38
-rw-r--r--build/export_generators/ide-gradle/repositories.jinja (renamed from build/export_generators/ide-gradle/bucket.jinja)0
-rw-r--r--build/export_generators/ide-gradle/source_sets.jinja36
-rw-r--r--build/export_generators/ide-gradle/test.jinja22
-rw-r--r--build/export_generators/ide-gradle/vars.jinja27
24 files changed, 311 insertions, 312 deletions
diff --git a/build/export_generators/gradle/build.gradle.kts.jinja b/build/export_generators/gradle/build.gradle.kts.jinja
index cea40219c0..ccf0a34e6e 100644
--- a/build/export_generators/gradle/build.gradle.kts.jinja
+++ b/build/export_generators/gradle/build.gradle.kts.jinja
@@ -1,6 +1,6 @@
{%- set publish = target.publish -%}
{%- set mainClass = target.app_main_class -%}
-{%- set hasJunit5Test = extra_targets|selectattr('junit5_test') -%}
+{%- set has_junit5_test = extra_targets|selectattr('junit5_test') -%}
plugins {
{% if mainClass -%}
`application`
@@ -34,7 +34,7 @@ java {
}
dependencies {
-{% if hasJunit5Test -%}
+{% if has_junit5_test -%}
testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
api("org.apache.commons:commons-math3:3.6.1")
api("com.google.guava:guava:31.0.1-jre")
@@ -71,7 +71,7 @@ dependencies {
{% endfor -%}
}
-{% if hasJunit5Test -%}
+{% if has_junit5_test -%}
tasks.named<Test>("test") {
useJUnitPlatform()
}
diff --git a/build/export_generators/ide-gradle/build.gradle.kts.jinja b/build/export_generators/ide-gradle/build.gradle.kts.jinja
index 18375ec2c6..36aa47faa9 100644
--- a/build/export_generators/ide-gradle/build.gradle.kts.jinja
+++ b/build/export_generators/ide-gradle/build.gradle.kts.jinja
@@ -1,124 +1,21 @@
-{%- set has_errorprone = target.consumer|selectattr('jar', 'startsWith', 'contrib/java/com/google/errorprone/error_prone_annotations')|length -%}
-{%- if has_errorprone -%}
-import net.ltgt.gradle.errorprone.CheckSeverity
-import net.ltgt.gradle.errorprone.errorprone
-
-{% endif -%}
-
-{%- include "[generator]/builddir.jinja" %}
-
-{%- macro OutDirs(runs, prefix, suffix) -%}
-{%- if run.args|length and run.out_dir|length -%}
-{%- for out_dir in run.out_dir -%}
-{#- search all run arguments ended by /<out_dir> -#}
-{%- set out_dirs = select_by_ends(run.args, "/" + out_dir) -%}
-{%- if out_dirs|length %}
-{{ prefix }}{{ out_dirs|first }}{{ suffix }}
-{%- endif -%}
-{%- endfor -%}
-{%- endif -%}
-{%- endmacro %}
-
-{%- 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') -%}
-
-{%- if not target.required_jdk -%}
-{%- set has_required_jdk = false -%}
-{#- If no required JDK, set default JDK for Kotlin parts -#}
-{%- set required_jdk = '17' -%}
-{%- else -%}
-{%- set has_required_jdk = true -%}
-{%- set required_jdk = target.required_jdk -%}
-{%- endif %}
-
-{% include "[generator]/plugins.jinja" -%}
+{%- include "[generator]/vars.jinja" -%}
+{%- include "[generator]/import.jinja" -%}
+{%- include "[generator]/repositories.jinja" -%}
+{%- include "[generator]/builddir.jinja" -%}
+{%- include "[generator]/plugins.jinja" -%}
{%- include "[generator]/kotlin_plugins.jinja" -%}
{%- include "[generator]/publish.jinja" -%}
{%- include "[generator]/preview.jinja" -%}
-
-{#- javac flags -#}
-{%- if target.javac.flags|length -%}
-{#- skip errorprone options -#}
-{%- set javac_flags = target.javac.flags|reject('startsWith', '-Xep:')|reject('startsWith', '-XepOpt:') -%}
-{%- if javac_flags|length and javac_flags != ['-parameters'] %}
-
-tasks.withType<JavaCompile> {
-{%- for javac_flag in javac_flags %}
- options.compilerArgs.add("{{ javac_flag }}")
-{%- endfor %}
-}
-{% endif -%}
-{%- endif -%}
-
-{%- include "[generator]/errorprone.jinja" %}
-{% include "[generator]/bucket.jinja" %}
-val project_root = "{{ arcadia_root }}"
-
-{% 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 -%}
-
-{%- include "[generator]/source_sets.jinja" %}
-
-{% include "[generator]/dependencies.jinja" -%}
-
-{%- if hasJunit5Test %}
-
-tasks.named<Test>("test") {
- useJUnitPlatform()
-}
-{% endif -%}
-
+{%- include "[generator]/configuration.jinja" -%}
+{%- include "[generator]/javac_flags.jinja" -%}
+{%- include "[generator]/errorprone.jinja" -%}
+{%- include "[generator]/source_sets.jinja" -%}
+{%- include "[generator]/test.jinja" -%}
+{%- include "[generator]/javadoc.jinja" -%}
{%- include "[generator]/run_java_program.jinja" -%}
-
-{% 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<Javadoc>().configureEach {
- isEnabled = false
-}
-
+{%- include "[generator]/dependencies.jinja" -%}
+{%- include "extra-tests.gradle.kts" ignore missing -%}
+{%- if publish -%}
+{%- include 'publish.gradle.kts' ignore missing -%}
+{%- endif -%}
{%- include "[generator]/debug.jinja" ignore missing -%}
diff --git a/build/export_generators/ide-gradle/build.gradle.kts.proto.jinja b/build/export_generators/ide-gradle/build.gradle.kts.proto.jinja
index 0f090a4a69..32be770844 100644
--- a/build/export_generators/ide-gradle/build.gradle.kts.proto.jinja
+++ b/build/export_generators/ide-gradle/build.gradle.kts.proto.jinja
@@ -1,172 +1,13 @@
-{%- set publish = target.publish -%}
-{%- set libraries = target.consumer|selectattr('type', 'eq', 'library') -%}
-import com.google.protobuf.gradle.*
-
-{% include "[generator]/builddir.jinja" %}
-
-val mainProtosDir = File(buildDir, "main_protos")
-{%- if libraries|length %}
-val mainExtractedIncludeProtosDir = File(buildDir, "extracted-include-protos/main")
-{%- endif %}
-
-plugins {
- id("java-library")
- id("com.google.protobuf") version "0.8.19"
-{%- if publish %}
- `maven-publish`
- `signing`
-{%- endif %}
-}
-{%- include "[generator]/publish.jinja" %}
-
-{% include "[generator]/bucket.jinja" %}
-val project_root = "{{ arcadia_root }}"
-
-sourceSets {
- main {
- java.srcDir("$buildDir/generated/sources/proto/main/java")
-{%- if target.proto_grpc %}
- java.srcDir("$buildDir/generated/sources/proto/main/grpc")
-{%- endif %}
- }
- test {
- java.srcDir("$buildDir/generated/sources/proto/test/java")
-{%- if target.proto_grpc %}
- java.srcDir("$buildDir/generated/sources/proto/test/grpc")
-{%- endif %}
- }
-}
-
-java {
- withSourcesJar()
- withJavadocJar()
-}
-
-configurations.api {
- isTransitive = false
-}
-
-configurations.implementation {
- isTransitive = false
-}
-
-configurations.testImplementation {
- isTransitive = false
-}
-
-{%- 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 %}
-
-dependencies {
-{%- for library in target.consumer if library.classpath -%}
-{%- if library.prebuilt and library.jar and (library.type != "contrib" or target.handler.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" %}
- implementation
-{%- else %}
- api
-{%- endif -%}({{ classpath }})
-{%- if library.excludes.consumer is defined %} {
-{% for exclude in library.excludes.consumer -%}
-{% set classpath = exclude.classpath|replace('"','') -%}
-{% set classpath_parts = split(classpath, ':') -%}
- exclude(group = "{{ classpath_parts[0] }}", module = "{{ classpath_parts[1] }}")
-{% endfor -%}
- }
-{%- endif -%}
-{%- endif -%}
-{%- endfor -%}
-
-{%- if target.proto_namespace %}
- protobuf(files(File(mainProtosDir, "{{ target.proto_namespace }}")))
-{%- else %}
- protobuf(files(mainProtosDir))
-{%- endif %}
-}
-
-protobuf {
- generatedFilesBaseDir = "$buildDir/generated/sources/proto"
-
- protoc {
- // Download from repositories
- artifact = "com.google.protobuf:protoc:{%- if target.proto_compiler_version -%}{{ target.proto_compiler_version }}{%- else -%}3.22.5{%- endif -%}"
- }
-{%- if target.proto_grpc %}
-
- plugins {
- id("grpc") {
- artifact = "io.grpc:protoc-gen-grpc-java:{%- if target.proto_grpc_version -%}{{ target.proto_grpc_version }}{%- else -%}1.45.0{%- endif -%}"
- }
-{%- if target.proto_kotlin_grpc %}
- id("grpckt") {
- artifact = "io.grpc:protoc-gen-grpc-kotlin:{%- if target.proto_kotlin_grpc_version -%}{{ target.proto_kotlin_grpc_version }}{%- else -%}1.3.1{%- endif -%}:jdk8@jar"
- }
-{%- endif %}
- }
-
- generateProtoTasks {
- all().forEach {
- it.plugins {
- id("grpc")
-{%- if target.proto_kotlin_grpc %}
- id("grpckt")
-{%- endif %}
- }
-{%- if target.proto_kotlin_grpc %}
- it.builtins {
- create("kotlin")
- }
-{%- endif %}
- }
- }
-{%- endif %}
-}
-
-val prepareMainProtos = tasks.register<Copy>("prepareMainProtos") {
- from("$project_root") {
-{#- list of all current project proto files -#}
-{%- for proto in target.proto_files %}
- include("{{ proto }}")
-{%- endfor %}
- }
- into(mainProtosDir)
-}
-
-{% if libraries|length -%}
-val extractMainLibrariesProtos = tasks.register<Copy>("extractMainLibrariesProtos") {
- from("$project_root") {
-{#- list of all library directories -#}
-{%- for library in libraries -%}
-{%- set path_and_jar = rsplit(library.jar, '/', 2) %}
- include("{{ path_and_jar[0] }}/**/*.proto")
-{%- endfor %}
- }
- into(mainExtractedIncludeProtosDir)
-}
-
-{% endif -%}
-afterEvaluate {
- tasks.getByName("extractProto").dependsOn(prepareMainProtos)
-{%- if libraries|length %}
- tasks.getByName("extractProto").dependsOn(extractMainLibrariesProtos)
-{%- endif %}
-}
-
-{# To avoid problems when build project with proto #}
-tasks.getByName("sourcesJar").dependsOn("generateProto")
-
-{# To disable redundant javadoc (it may fail the build) #}
-tasks.withType<Javadoc>().configureEach {
- isEnabled = false
-}
-
+{%- include "[generator]/proto_vars.jinja" -%}
+{%- include "[generator]/proto_import.jinja" -%}
+{%- include "[generator]/repositories.jinja" -%}
+{%- include "[generator]/proto_builddir.jinja" -%}
+{%- include "[generator]/proto_plugins.jinja" -%}
+{%- include "[generator]/publish.jinja" -%}
+{%- include "[generator]/proto_configuration.jinja" -%}
+{%- include "[generator]/proto_source_sets.jinja" -%}
+{%- include "[generator]/protobuf.jinja" -%}
+{%- include "[generator]/proto_prepare.jinja" -%}
+{%- include "[generator]/javadoc.jinja" -%}
+{%- include "[generator]/proto_dependencies.jinja" -%}
{%- include "[generator]/debug.jinja" ignore missing -%}
diff --git a/build/export_generators/ide-gradle/builddir.jinja b/build/export_generators/ide-gradle/builddir.jinja
index 83af50e603..f3fb92f3ce 100644
--- a/build/export_generators/ide-gradle/builddir.jinja
+++ b/build/export_generators/ide-gradle/builddir.jinja
@@ -1,3 +1,4 @@
+{#- empty string #}
val baseBuildDir = "{{ export_root }}/gradle.build/"
buildDir = file(baseBuildDir + project.path.replaceFirst(":", "/").replace(":", "."))
subprojects {
diff --git a/build/export_generators/ide-gradle/configuration.jinja b/build/export_generators/ide-gradle/configuration.jinja
new file mode 100644
index 0000000000..b238ca95bf
--- /dev/null
+++ b/build/export_generators/ide-gradle/configuration.jinja
@@ -0,0 +1,25 @@
+{#- empty string #}
+val project_root = "{{ arcadia_root }}"
+
+{% if mainClass -%}
+application {
+ mainClass.set("{{ mainClass }}")
+}
+
+{% endif -%}
+java {
+ withSourcesJar()
+ withJavadocJar()
+}
+
+configurations.api {
+ isTransitive = false
+}
+
+configurations.implementation {
+ isTransitive = false
+}
+
+configurations.testImplementation {
+ isTransitive = false
+}
diff --git a/build/export_generators/ide-gradle/dependencies.jinja b/build/export_generators/ide-gradle/dependencies.jinja
index cbc58b7d20..cf12326bbf 100644
--- a/build/export_generators/ide-gradle/dependencies.jinja
+++ b/build/export_generators/ide-gradle/dependencies.jinja
@@ -1,3 +1,4 @@
+{#- empty string #}
dependencies {
{%- for library in target.consumer if library.classpath -%}
{%- if has_errorprone -%}
diff --git a/build/export_generators/ide-gradle/errorprone.jinja b/build/export_generators/ide-gradle/errorprone.jinja
index bd3e82a455..ff48d8b5d0 100644
--- a/build/export_generators/ide-gradle/errorprone.jinja
+++ b/build/export_generators/ide-gradle/errorprone.jinja
@@ -1,7 +1,6 @@
{%- if has_errorprone -%}
{%- set ep_flags = target.javac.flags|select('startsWith', '-Xep:') -%}
{%- if ep_flags|length or ep_opts|length %}
-
tasks.withType<JavaCompile> {
{%- if ep_flags|length %}
options.errorprone.checks.set(
diff --git a/build/export_generators/ide-gradle/import.jinja b/build/export_generators/ide-gradle/import.jinja
new file mode 100644
index 0000000000..71000d49d8
--- /dev/null
+++ b/build/export_generators/ide-gradle/import.jinja
@@ -0,0 +1,5 @@
+{%- if has_errorprone -%}
+import net.ltgt.gradle.errorprone.CheckSeverity
+import net.ltgt.gradle.errorprone.errorprone
+
+{% endif -%}
diff --git a/build/export_generators/ide-gradle/javac_flags.jinja b/build/export_generators/ide-gradle/javac_flags.jinja
new file mode 100644
index 0000000000..c563045e69
--- /dev/null
+++ b/build/export_generators/ide-gradle/javac_flags.jinja
@@ -0,0 +1,12 @@
+{%- if target.javac.flags|length -%}
+{#- skip errorprone options -#}
+{%- set javac_flags = target.javac.flags|reject('startsWith', '-Xep:')|reject('startsWith', '-XepOpt:') -%}
+{%- if javac_flags|length and javac_flags != ['-parameters'] %}
+
+tasks.withType<JavaCompile> {
+{%- for javac_flag in javac_flags %}
+ options.compilerArgs.add("{{ javac_flag }}")
+{%- endfor %}
+}
+{% endif -%}
+{%- endif -%}
diff --git a/build/export_generators/ide-gradle/javadoc.jinja b/build/export_generators/ide-gradle/javadoc.jinja
new file mode 100644
index 0000000000..94fc8c750f
--- /dev/null
+++ b/build/export_generators/ide-gradle/javadoc.jinja
@@ -0,0 +1,4 @@
+{#- To disable redundant javadoc (it may fail the build) #}
+tasks.withType<Javadoc>().configureEach {
+ isEnabled = false
+}
diff --git a/build/export_generators/ide-gradle/plugins.jinja b/build/export_generators/ide-gradle/plugins.jinja
index 22ade9b111..13a46003be 100644
--- a/build/export_generators/ide-gradle/plugins.jinja
+++ b/build/export_generators/ide-gradle/plugins.jinja
@@ -1,3 +1,4 @@
+{#- empty string #}
plugins {
{%- if mainClass %}
`application`
@@ -42,4 +43,4 @@ java {
languageVersion = JavaLanguageVersion.of("{{ required_jdk }}")
}
}
-{% endif -%}
+{%- endif -%}
diff --git a/build/export_generators/ide-gradle/proto_builddir.jinja b/build/export_generators/ide-gradle/proto_builddir.jinja
new file mode 100644
index 0000000000..ac50a1d33b
--- /dev/null
+++ b/build/export_generators/ide-gradle/proto_builddir.jinja
@@ -0,0 +1,5 @@
+{%- include "[generator]/builddir.jinja" %}
+val mainProtosDir = File(buildDir, "main_protos")
+{%- if libraries|length %}
+val mainExtractedIncludeProtosDir = File(buildDir, "extracted-include-protos/main")
+{%- endif %}
diff --git a/build/export_generators/ide-gradle/proto_configuration.jinja b/build/export_generators/ide-gradle/proto_configuration.jinja
new file mode 100644
index 0000000000..5a9554b2ae
--- /dev/null
+++ b/build/export_generators/ide-gradle/proto_configuration.jinja
@@ -0,0 +1,19 @@
+{#- empty string #}
+val project_root = "{{ arcadia_root }}"
+
+java {
+ withSourcesJar()
+ withJavadocJar()
+}
+
+configurations.api {
+ isTransitive = false
+}
+
+configurations.implementation {
+ isTransitive = false
+}
+
+configurations.testImplementation {
+ isTransitive = false
+}
diff --git a/build/export_generators/ide-gradle/proto_dependencies.jinja b/build/export_generators/ide-gradle/proto_dependencies.jinja
new file mode 100644
index 0000000000..61bcc05fa9
--- /dev/null
+++ b/build/export_generators/ide-gradle/proto_dependencies.jinja
@@ -0,0 +1,32 @@
+{#- empty string #}
+dependencies {
+{%- for library in target.consumer if library.classpath -%}
+{%- if library.prebuilt and library.jar and (library.type != "contrib" or target.handler.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" %}
+ implementation
+{%- else %}
+ api
+{%- endif -%}({{ classpath }})
+{%- if library.excludes.consumer is defined %} {
+{% for exclude in library.excludes.consumer -%}
+{% set classpath = exclude.classpath|replace('"','') -%}
+{% set classpath_parts = split(classpath, ':') -%}
+ exclude(group = "{{ classpath_parts[0] }}", module = "{{ classpath_parts[1] }}")
+{% endfor -%}
+ }
+{%- endif -%}
+{%- endif -%}
+{%- endfor -%}
+
+{%- if target.proto_namespace %}
+ protobuf(files(File(mainProtosDir, "{{ target.proto_namespace }}")))
+{%- else %}
+ protobuf(files(mainProtosDir))
+{%- endif %}
+}
diff --git a/build/export_generators/ide-gradle/proto_import.jinja b/build/export_generators/ide-gradle/proto_import.jinja
new file mode 100644
index 0000000000..0425fe41f2
--- /dev/null
+++ b/build/export_generators/ide-gradle/proto_import.jinja
@@ -0,0 +1,3 @@
+import com.google.protobuf.gradle.*
+
+{# ^ empty string -#}
diff --git a/build/export_generators/ide-gradle/proto_plugins.jinja b/build/export_generators/ide-gradle/proto_plugins.jinja
new file mode 100644
index 0000000000..a5bb76d758
--- /dev/null
+++ b/build/export_generators/ide-gradle/proto_plugins.jinja
@@ -0,0 +1,9 @@
+{#- empty string #}
+plugins {
+ id("java-library")
+ id("com.google.protobuf") version "0.8.19"
+{%- if publish %}
+ `maven-publish`
+ `signing`
+{%- endif %}
+}
diff --git a/build/export_generators/ide-gradle/proto_prepare.jinja b/build/export_generators/ide-gradle/proto_prepare.jinja
new file mode 100644
index 0000000000..2ac84b5014
--- /dev/null
+++ b/build/export_generators/ide-gradle/proto_prepare.jinja
@@ -0,0 +1,32 @@
+{#- empty string #}
+val prepareMainProtos = tasks.register<Copy>("prepareMainProtos") {
+ from("$project_root") {
+{#- list of all current project proto files -#}
+{%- for proto in target.proto_files %}
+ include("{{ proto }}")
+{%- endfor %}
+ }
+ into(mainProtosDir)
+}
+
+{% if libraries|length -%}
+val extractMainLibrariesProtos = tasks.register<Copy>("extractMainLibrariesProtos") {
+ from("$project_root") {
+{#- list of all library directories -#}
+{%- for library in libraries -%}
+{%- set path_and_jar = rsplit(library.jar, '/', 2) %}
+ include("{{ path_and_jar[0] }}/**/*.proto")
+{%- endfor %}
+ }
+ into(mainExtractedIncludeProtosDir)
+}
+
+{% endif -%}
+afterEvaluate {
+ tasks.getByName("extractProto").dependsOn(prepareMainProtos)
+{%- if libraries|length %}
+ tasks.getByName("extractProto").dependsOn(extractMainLibrariesProtos)
+{%- endif %}
+}
+
+tasks.getByName("sourcesJar").dependsOn("generateProto")
diff --git a/build/export_generators/ide-gradle/proto_source_sets.jinja b/build/export_generators/ide-gradle/proto_source_sets.jinja
new file mode 100644
index 0000000000..fffe7301a6
--- /dev/null
+++ b/build/export_generators/ide-gradle/proto_source_sets.jinja
@@ -0,0 +1,22 @@
+{#- empty string #}
+sourceSets {
+ main {
+ java.srcDir("$buildDir/generated/sources/proto/main/java")
+{%- if target.proto_grpc %}
+ java.srcDir("$buildDir/generated/sources/proto/main/grpc")
+{%- endif %}
+ }
+ test {
+ java.srcDir("$buildDir/generated/sources/proto/test/java")
+{%- if target.proto_grpc %}
+ java.srcDir("$buildDir/generated/sources/proto/test/grpc")
+{%- 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 %}
diff --git a/build/export_generators/ide-gradle/proto_vars.jinja b/build/export_generators/ide-gradle/proto_vars.jinja
new file mode 100644
index 0000000000..45fa6d7bb7
--- /dev/null
+++ b/build/export_generators/ide-gradle/proto_vars.jinja
@@ -0,0 +1,2 @@
+{%- set publish = target.publish -%}
+{%- set libraries = target.consumer|selectattr('type', 'eq', 'library') -%}
diff --git a/build/export_generators/ide-gradle/protobuf.jinja b/build/export_generators/ide-gradle/protobuf.jinja
new file mode 100644
index 0000000000..6803206957
--- /dev/null
+++ b/build/export_generators/ide-gradle/protobuf.jinja
@@ -0,0 +1,38 @@
+{#- empty string #}
+protobuf {
+ generatedFilesBaseDir = "$buildDir/generated/sources/proto"
+
+ protoc {
+ // Download from repositories
+ artifact = "com.google.protobuf:protoc:{%- if target.proto_compiler_version -%}{{ target.proto_compiler_version }}{%- else -%}3.22.5{%- endif -%}"
+ }
+{%- if target.proto_grpc %}
+
+ plugins {
+ id("grpc") {
+ artifact = "io.grpc:protoc-gen-grpc-java:{%- if target.proto_grpc_version -%}{{ target.proto_grpc_version }}{%- else -%}1.45.0{%- endif -%}"
+ }
+{%- if target.proto_kotlin_grpc %}
+ id("grpckt") {
+ artifact = "io.grpc:protoc-gen-grpc-kotlin:{%- if target.proto_kotlin_grpc_version -%}{{ target.proto_kotlin_grpc_version }}{%- else -%}1.3.1{%- endif -%}:jdk8@jar"
+ }
+{%- endif %}
+ }
+
+ generateProtoTasks {
+ all().forEach {
+ it.plugins {
+ id("grpc")
+{%- if target.proto_kotlin_grpc %}
+ id("grpckt")
+{%- endif %}
+ }
+{%- if target.proto_kotlin_grpc %}
+ it.builtins {
+ create("kotlin")
+ }
+{%- endif %}
+ }
+ }
+{%- endif %}
+}
diff --git a/build/export_generators/ide-gradle/bucket.jinja b/build/export_generators/ide-gradle/repositories.jinja
index b55fc07ae5..b55fc07ae5 100644
--- a/build/export_generators/ide-gradle/bucket.jinja
+++ b/build/export_generators/ide-gradle/repositories.jinja
diff --git a/build/export_generators/ide-gradle/source_sets.jinja b/build/export_generators/ide-gradle/source_sets.jinja
index eb722877bf..47dc8a8180 100644
--- a/build/export_generators/ide-gradle/source_sets.jinja
+++ b/build/export_generators/ide-gradle/source_sets.jinja
@@ -1,20 +1,4 @@
-{%- 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 %}
-
+{#- empty string #}
sourceSets {
{%- if target.runs|length %}
main {
@@ -55,3 +39,21 @@ sourceSets {
{%- endfor %}
}
}
+
+{%- if target.jar_source_set|length -%}
+{%- 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|length -%}
+{%- 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 -%}
diff --git a/build/export_generators/ide-gradle/test.jinja b/build/export_generators/ide-gradle/test.jinja
new file mode 100644
index 0000000000..fcfcd8f93e
--- /dev/null
+++ b/build/export_generators/ide-gradle/test.jinja
@@ -0,0 +1,22 @@
+{%- 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 has_junit5_test %}
+tasks.named<Test>("test") {
+ useJUnitPlatform()
+}
+{% endif -%}
diff --git a/build/export_generators/ide-gradle/vars.jinja b/build/export_generators/ide-gradle/vars.jinja
new file mode 100644
index 0000000000..db363b3cbc
--- /dev/null
+++ b/build/export_generators/ide-gradle/vars.jinja
@@ -0,0 +1,27 @@
+{%- set mainClass = target.app_main_class -%}
+{%- set publish = target.publish -%}
+{%- set with_kotlin = target.with_kotlin -%}
+{%- set kotlin_version = target.kotlin_version -%}
+{%- set has_junit5_test = extra_targets|selectattr('junit5_test') -%}
+{%- set has_errorprone = target.consumer|selectattr('jar', 'startsWith', 'contrib/java/com/google/errorprone/error_prone_annotations')|length -%}
+
+{%- if not target.required_jdk -%}
+{%- set has_required_jdk = false -%}
+{#- If no required JDK, set default JDK for Kotlin parts -#}
+{%- set required_jdk = '17' -%}
+{%- else -%}
+{%- set has_required_jdk = true -%}
+{%- set required_jdk = target.required_jdk -%}
+{%- endif -%}
+
+{%- macro OutDirs(runs, prefix, suffix) -%}
+{%- if run.args|length and run.out_dir|length -%}
+{%- for out_dir in run.out_dir -%}
+{#- search all run arguments ended by /<out_dir> -#}
+{%- set out_dirs = select_by_ends(run.args, "/" + out_dir) -%}
+{%- if out_dirs|length %}
+{{ prefix }}{{ out_dirs|first }}{{ suffix }}
+{%- endif -%}
+{%- endfor -%}
+{%- endif -%}
+{%- endmacro -%}