{%- set publish = target.publish -%} import com.google.protobuf.gradle.* val buildProtoDir = File("${buildDir}", "__proto__") plugins { id("java-library") id("com.google.protobuf") version "0.8.19" {%- if publish %} `maven-publish` `signing` {%- endif -%} } {%- if publish %} group = "{{ target.publish_group }}" version = {% if target.publish_version -%}"{{ target.publish_version }}"{%- else -%}project.properties["version"]{%- endif %} {%- 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" } } } } sourceSets { main { java.srcDir("build/generated/source/proto") } } val project_root="{%- if export_root.startswith(arcadia_root + '/') -%}{{ arcadia_root }}{%- else -%}{{ export_root }}{%- 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(buildProtoDir, "{{ target.proto_namespace }}"))) {% else -%} protobuf(files(buildProtoDir)) {% endif -%} } protobuf { 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 is defined -%} plugins { id("grpc") { artifact = "io.grpc:protoc-gen-grpc-java:{%- if target.proto_grpc_version -%}{{ target.proto_grpc_version }}{%- else -%}1.45.0{%- endif -%}" } } generateProtoTasks { all().forEach { it.plugins { id("grpc") } } } {%- endif %} } val prepareProto = tasks.register("prepareProto") { from(rootDir) { {%- for proto in target.proto_files %} include("{{ proto }}") {%- endfor %} {# Mining proto-deps sources directories #} {%- for library in target.consumer if library.prebuilt -%} {%- if library.type == "library" %} {%- set proto_rep = library.classpath|replace('project(":','') %} {%- set proto_rep = proto_rep|replace('")','') %} {%- set proto_rep = proto_rep|replace(':','/') %} {%- set proto = proto_rep + '/**' %} include("{{ proto }}") {%- endif -%} {%- endfor %} } into(buildProtoDir) } afterEvaluate { tasks.getByName("extractProto").dependsOn(prepareProto) } {# To avoid problems when build project with proto #} tasks.named("sourcesJar").configure { dependsOn("generateProto") } {# To disable redundant javadoc (it may fail the build) #} tasks.withType().configureEach { isEnabled = false } {%- include "[generator]/debug.jinja" ignore missing -%}