1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import com.google.protobuf.gradle.*
- val buildProtoDir = File("${buildDir}", "__proto__")
- plugins {
- id("java-library")
- id("com.google.protobuf") version "0.8.19"
- {% if targets|selectattr('publish') -%}
- `maven-publish`
- `signing`
- {% endif -%}
- }
- {% if targets|selectattr('publish') -%}
- group = "{{ targets[0].publish_group }}"
- version = project.properties["version"]
- {% endif -%}
- repositories {
- mavenCentral()
- }
- java {
- withSourcesJar()
- withJavadocJar()
- }
- dependencies {
- {% if targets[0].consumer is defined -%}
- {%- for library in targets[0].consumer -%}
- api({{ library.classpath }})
- {% endfor -%}
- {%- endif -%}
- {% if targets[0].proto_namespace is defined -%}
- protobuf(files(File(buildProtoDir, "{{ targets[0].proto_namespace }}")))
- {% else -%}
- protobuf(files(buildProtoDir))
- {% endif -%}
- }
- protobuf {
- protoc {
- // Download from repositories
- artifact = "com.google.protobuf:protoc:
- {%- if targets[0].proto_compiler_version is defined -%}
- {{ targets[0].proto_compiler_version }}
- {%- else -%}
- 3.22.5
- {%- endif -%}
- "
- }
- {% if targets[0].proto_grpc is defined -%}
- plugins {
- id("grpc") {
- artifact = "io.grpc:protoc-gen-grpc-java:1.45.0"
- }
- }
- generateProtoTasks {
- ofSourceSet("main").forEach {
- it.plugins {
- id("grpc")
- }
- }
- }
- {%- endif %}
- }
- val prepareProto = tasks.register<Copy>("prepareProto") {
- from(rootDir) {
- {% for proto in targets[0].proto_files -%}
- include("{{ proto }}")
- {% endfor -%}
- }
- into(buildProtoDir)
- }
- afterEvaluate {
- tasks.getByName("extractProto").dependsOn(prepareProto)
- }
- {% if targets|selectattr('publish') -%}
- {% include 'publish.gradle.kts' -%}
- {% endif -%}
|