forked from grpc/grpc-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
157 lines (139 loc) · 5.42 KB
/
build.gradle
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
plugins {
id 'com.google.protobuf' version '0.8.11'
// Generate IntelliJ IDEA's .idea & .iml project files
// Starting with 0.8.4 of protobuf-gradle-plugin, *.proto and the gen output files are added
// to IntelliJ as sources. It is no longer necessary to add them manually to the idea {} block
// to jump to definitions from Java and Kotlin files.
// For best results, install the Protobuf and Kotlin plugins for IntelliJ.
id 'idea'
// Provide convenience executables for trying out the examples.
id 'application'
id 'maven-publish'
id 'edu.sc.seis.launch4j' version '2.4.4'
id 'com.github.johnrengelman.shadow' version '4.0.2'
}
description = 'The protoc plugin for gRPC Kotlin'
mainClassName = 'io.grpc.kotlin.generator.GeneratorRunner'
repositories {
google()
jcenter()
mavenCentral()
mavenLocal()
}
dependencies {
// Kotlin and Java
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${rootProject.ext.coroutinesVersion}"
implementation "javax.annotation:javax.annotation-api:1.2"
// Grpc and Protobuf
implementation project(':grpc-kotlin-stub')
implementation "com.google.protobuf:protobuf-java:${rootProject.ext.protobufVersion}"
implementation "io.grpc:grpc-protobuf:${rootProject.ext.grpcVersion}"
implementation "io.grpc:grpc-stub:${rootProject.ext.grpcVersion}"
implementation "io.grpc:grpc-netty-shaded:${rootProject.ext.grpcVersion}"
// Misc
implementation 'com.squareup:kotlinpoet:1.5.0'
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.61"
implementation "com.google.truth:truth:1.0.1"
// Testing
testImplementation "junit:junit:4.12"
testImplementation "com.google.guava:guava:28.2-jre"
testImplementation "com.google.jimfs:jimfs:1.1"
testImplementation 'com.google.protobuf:protobuf-gradle-plugin:0.8.11'
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.5.2"
testImplementation "org.mockito:mockito-core:2.28.2"
}
protobuf {
protoc { artifact = "com.google.protobuf:protoc:${rootProject.ext.protobufVersion}" }
plugins {
// Specify protoc to generate using kotlin protobuf plugin
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:${rootProject.ext.grpcVersion}"
}
// Specify protoc to generate using our grpc kotlin plugin
grpckt {
path = "$buildDir/install/grpc-kotlin-compiler/bin/grpc-kotlin-compiler"
}
}
generateProtoTasks {
all().each { task ->
if (task.name.startsWith('generateTestProto')) {
task.dependsOn { installDist }
}
task.plugins {
// Generate Java gRPC classes
grpc { }
// Generate Kotlin gRPC using the custom plugin from library
grpckt { }
}
}
}
}
task prependShellStub() {
doLast {
def stub = file("stub.sh")
def plugin = new File("${buildDir}/artifacts/protoc-gen-grpc-kotlin")
def tempScript = new File("${buildDir}/artifacts/protoc-gen-grpc-kotlin.stubbed")
tempScript.write('') // truncate output if needed
tempScript << stub.text.normalize() // remove carriage returns
tempScript << plugin.bytes
plugin.delete()
tempScript.renameTo(plugin)
plugin.setExecutable(true)
}
}
publishing {
publications {
maven(MavenPublication) {
from components.java
// Removes all artifacts since grpc-kotlin-compiler doesn't generate any
artifacts = []
artifactId 'protoc-gen-grpc-kotlin'
artifact("$buildDir/artifacts/protoc-gen-grpc-kotlin" as File) {
classifier "osx-x86_64"
extension "exe"
builtBy prependShellStub
}
artifact("$buildDir/artifacts/protoc-gen-grpc-kotlin" as File) {
classifier "linux-x86_64"
extension "exe"
builtBy prependShellStub
}
artifact("$buildDir/artifacts/protoc-gen-grpc-kotlin-windows-x86_64.exe" as File) {
classifier "windows-x86_64"
extension "exe"
builtBy createExe
}
pom.withXml {
// This isn't any sort of Java archive artifact, and OSSRH doesn't enforce
// javadoc for 'pom' packages. 'exe' would be a more appropriate packaging
// value, but it isn't clear how that will be interpreted. In addition,
// 'pom' is typically the value used when building an exe with Maven.
asNode().project.packaging*.value = 'pom'
}
}
}
}
launch4j {
outfile = "protoc-gen-grpc-kotlin-windows-x86_64.exe"
mainClassName = mainClassName
outputDir = "artifacts"
jar = '../artifacts/protoc-gen-grpc-kotlin'
jreMinVersion = JavaVersion.VERSION_1_7
}
shadowJar {
mergeServiceFiles()
exclude 'META-INF/*.SF'
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
manifest {
attributes("Main-Class": mainClassName,
"Implementation-Version": version)
}
archiveName = "protoc-gen-grpc-kotlin"
destinationDir = "$buildDir/artifacts" as File
}
createExe.dependsOn(shadowJar)
prependShellStub.dependsOn(test)
prependShellStub.dependsOn(shadowJar)
prependShellStub.dependsOn(createExe)