aboutsummaryrefslogtreecommitdiffstats
path: root/build/export_generators/ide-gradle/build.gradle.kts.proto.jinja
blob: f1da347c1588bcb4eca4470cabdd7a8b350918f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
{%- set publish = target.publish -%}
import com.google.protobuf.gradle.*

val baseBuildDir = "{{ export_root }}/gradle.build/"
buildDir = file(baseBuildDir + project.path.replaceFirst(":", "/").replace(":", "."))
subprojects {
    buildDir = file(baseBuildDir + project.path.replaceFirst(":", "/").replace(":", "."))
}

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 = "{{ arcadia_root }}"

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 -%}
    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 prepareProto = tasks.register<Copy>("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<Javadoc>().configureEach {
    isEnabled = false
}

{%- include "[generator]/debug.jinja" ignore missing -%}