Skip to content

Commit 5b6b64a

Browse files
authored
Split maven packages (#42)
2 parents f5b2342 + e4a9d35 commit 5b6b64a

File tree

84 files changed

+396
-188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+396
-188
lines changed

build.gradle

Lines changed: 109 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,125 @@
11
plugins {
2-
id 'org.jetbrains.kotlin.jvm' version'1.3.61'
3-
id 'com.google.protobuf' version '0.8.8'
4-
id 'org.jetbrains.dokka' version '0.10.1'
5-
6-
// Generate IntelliJ IDEA's .idea & .iml project files
7-
// Starting with 0.8.4 of protobuf-gradle-plugin, *.proto and the gen output files are added
8-
// to IntelliJ as sources. It is no longer necessary to add them manually to the idea {} block
9-
// to jump to definitions from Java and Kotlin files.
10-
// For best results, install the Protobuf and Kotlin plugins for IntelliJ.
11-
id 'idea'
12-
13-
// Provide convenience executables for trying out the examples.
14-
id 'application'
15-
id 'maven-publish'
2+
id 'org.jetbrains.kotlin.jvm' version'1.3.61' apply false
163
}
174

18-
mainClassName = 'io.grpc.kotlin.generator.GeneratorRunner'
19-
applicationName = 'grpc-kotlin'
20-
21-
repositories {
22-
google()
23-
jcenter()
24-
mavenCentral()
25-
mavenLocal()
5+
ext {
6+
grpcVersion = '1.28.0' // CURRENT_GRPC_VERSION
7+
protobufVersion = '3.11.0'
8+
coroutinesVersion = '1.3.3'
269
}
2710

28-
// Feel free to delete the comment at the next line. It is just for safely
29-
// updating the version in our release process.
30-
def grpcVersion = '1.26.0' // CURRENT_GRPC_VERSION
31-
def coroutinesVersion = '1.3.3'
32-
def kotlinVersion = '1.3.61'
33-
34-
dependencies {
35-
// Kotlin
36-
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:${coroutinesVersion}"
11+
subprojects {
12+
apply plugin: 'org.jetbrains.kotlin.jvm'
3713

38-
// Grpc and Protobuf
39-
compile 'com.google.protobuf:protobuf-java:3.11.0'
40-
compile "io.grpc:grpc-netty-shaded:${grpcVersion}"
41-
compile "io.grpc:grpc-protobuf:${grpcVersion}"
42-
compile "io.grpc:grpc-stub:${grpcVersion}"
14+
group = "io.grpc"
15+
version = "0.1.0" // CURRENT_GRPC_KOTLIN_VERSION
4316

44-
// Java
45-
compile "javax.annotation:javax.annotation-api:1.2"
17+
plugins.withId("org.jetbrains.dokka") {
18+
dokka {
19+
outputFormat = 'html'
20+
outputDirectory = "$buildDir/dokka"
21+
configuration {
22+
externalDocumentationLink {
23+
url = new URL("http://grpc.github.io/grpc-java/javadoc/")
24+
}
25+
externalDocumentationLink {
26+
url = new URL("http://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/")
27+
}
28+
perPackageOption {
29+
prefix = "io.grpc.testing"
30+
suppress = true
31+
}
32+
perPackageOption {
33+
prefix = "io.grpc.kotlin.generator"
34+
suppress = true
35+
}
36+
}
37+
}
38+
}
4639

47-
// Misc
48-
compile 'com.squareup:kotlinpoet:1.5.0'
49-
compile "org.jetbrains.kotlin:kotlin-reflect:1.3.61"
50-
compile "com.google.truth:truth:1.0.1"
40+
plugins.withId("maven-publish") {
41+
publishing {
42+
publications {
43+
maven(MavenPublication) {
44+
pom {
45+
name = project.group + ":" + project.name
46+
url = 'https://github.com/grpc/grpc-kotlin'
47+
afterEvaluate {
48+
// description is not available until evaluated.
49+
description = project.description
50+
}
51+
52+
scm {
53+
connection = 'scm:git:https://github.com/grpc/grpc-kotlin.git'
54+
developerConnection = 'scm:git:[email protected]:grpc/grpc-kotlin.git'
55+
url = 'https://github.com/grpc/grpc-kotlin'
56+
}
57+
58+
licenses {
59+
license {
60+
name = 'Apache 2.0'
61+
url = 'https://opensource.org/licenses/Apache-2.0'
62+
}
63+
}
64+
65+
developers {
66+
developer {
67+
id = "grpc.io"
68+
name = "gRPC Contributors"
69+
70+
url = "https://grpc.io/"
71+
organization = "gRPC Authors"
72+
organizationUrl = "https://www.google.com"
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}
5179

52-
// Testing
53-
testImplementation "com.google.guava:guava:28.2-jre"
54-
testImplementation "com.google.jimfs:jimfs:1.1"
55-
testImplementation 'com.google.protobuf:protobuf-gradle-plugin:0.8.11'
56-
testImplementation "com.google.truth.extensions:truth-proto-extension:1.0"
57-
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
58-
testImplementation "io.grpc:grpc-testing:${grpcVersion}" // gRCP testing utilities
59-
testImplementation "junit:junit:4.12"
60-
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.5.2"
61-
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.3.2'
62-
testImplementation "org.jetbrains.kotlin:kotlin-android-extensions:$kotlinVersion"
63-
testImplementation "org.mockito:mockito-core:2.28.2"
64-
}
80+
plugins.withId("java") {
81+
task javadocJar(type: Jar) {
82+
classifier = 'javadoc'
83+
from javadoc
84+
}
6585

66-
protobuf {
67-
protoc { artifact = 'com.google.protobuf:protoc:3.11.0' }
68-
plugins {
69-
// Specify protoc to generate using kotlin protobuf plugin
70-
grpc {
71-
artifact = 'io.grpc:protoc-gen-grpc-java:1.27.0'
72-
}
73-
// Specify protoc to generate using our grpc kotlin plugin
74-
grpckt {
75-
path = 'build/install/grpc-kotlin/bin/grpc-kotlin'
76-
}
77-
}
78-
generateProtoTasks {
79-
all().each { task ->
80-
if (task.name.startsWith('generateTestProto')) {
81-
task.dependsOn { installDist }
86+
task sourcesJar(type: Jar) {
87+
classifier = 'sources'
88+
from sourceSets.main.allSource
8289
}
83-
task.plugins {
84-
// Generate Java gRPC classes
85-
grpc { }
86-
// Generate Kotlin gRPC using the custom plugin from library
87-
grpckt { }
90+
91+
// Generate the jar file to be used by our custom plugin
92+
task protocJar(type: Jar) {
93+
classifier "protoc"
94+
manifest {
95+
attributes 'Main-Class': 'io.grpc.kotlin.generator.GeneratorRunner'
96+
}
97+
baseName = project.name
98+
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
99+
with jar
88100
}
89-
}
90-
}
91-
}
92101

93-
dokka {
94-
outputFormat = 'html'
95-
outputDirectory = "$buildDir/dokka"
96-
configuration {
97-
externalDocumentationLink {
98-
url = new URL("http://grpc.github.io/grpc-java/javadoc/")
99-
}
100-
externalDocumentationLink {
101-
url = new URL("http://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/")
102-
}
103-
perPackageOption {
104-
prefix = "io.grpc.testing"
105-
suppress = true
106-
}
107-
perPackageOption {
108-
prefix = "io.grpc.kotlin.generator"
109-
suppress = true
102+
publishing {
103+
publications {
104+
maven {
105+
from components.java
106+
107+
artifact javadocJar
108+
artifact sourcesJar
109+
110+
if (project.name == 'protoc-gen-grpc-kotlin') {
111+
// Generate the artifacts expected by protobuf-gradle-plugin
112+
artifact protocJar
113+
artifactForGradlePlugin(it, 'linux', 'aarch_64')
114+
artifactForGradlePlugin(it, 'linux', 'x86_32')
115+
artifactForGradlePlugin(it, 'linux', 'x86_64')
116+
artifactForGradlePlugin(it, 'osx', 'x86_64')
117+
artifactForGradlePlugin(it, 'windows', 'x86_32')
118+
artifactForGradlePlugin(it, 'windows', 'x86_64')
119+
}
120+
}
121+
}
122+
}
110123
}
111124
}
112125
}
@@ -124,88 +137,3 @@ def artifactForGradlePlugin(MavenPublication pub, String os, String arch) {
124137
}
125138
}
126139
}
127-
128-
// Generate the jar file to be used by our custom plugin
129-
task protocJar(type: Jar) {
130-
classifier "protoc"
131-
manifest {
132-
attributes 'Main-Class': mainClassName
133-
}
134-
baseName = 'protoc-gen-grpc-kotlin'
135-
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
136-
with jar
137-
}
138-
139-
task javadocJar(type: Jar) {
140-
classifier = 'javadoc'
141-
from javadoc
142-
}
143-
144-
task sourcesJar(type: Jar) {
145-
classifier = 'sources'
146-
from sourceSets.main.allSource
147-
}
148-
149-
publishing {
150-
publications {
151-
maven(MavenPublication) {
152-
pom {
153-
name = 'grpc.io:grpc-kotlin'
154-
url = 'https://github.com/grpc/grpc-kotlin'
155-
afterEvaluate {
156-
// description is not available until evaluated.
157-
description = 'The protoc plugin for gRPC Kotlin'
158-
}
159-
160-
scm {
161-
connection = 'scm:git:https://github.com/grpc/grpc-kotlin.git'
162-
developerConnection = 'scm:git:[email protected]:grpc/grpc-kotlin.git'
163-
url = 'https://github.com/grpc/grpc-kotlin'
164-
}
165-
166-
licenses {
167-
license {
168-
name = 'Apache 2.0'
169-
url = 'https://opensource.org/licenses/Apache-2.0'
170-
}
171-
}
172-
173-
developers {
174-
developer {
175-
id = "grpc.io"
176-
name = "gRPC Contributors"
177-
178-
url = "https://grpc.io/"
179-
organization = "gRPC Authors"
180-
organizationUrl = "https://www.google.com"
181-
}
182-
}
183-
}
184-
185-
groupId = 'io.grpc'
186-
artifactId = 'grpc-kotlin'
187-
version = '0.1.0'
188-
from components.java
189-
190-
// Add a Fat JAR for the protoc plugin
191-
artifact protocJar
192-
artifact javadocJar
193-
artifact sourcesJar
194-
195-
// Generate the artifacts expected by protobuf-gradle-plugin
196-
artifactForGradlePlugin(it, 'linux', 'aarch_64')
197-
artifactForGradlePlugin(it, 'linux', 'x86_32')
198-
artifactForGradlePlugin(it, 'linux', 'x86_64')
199-
artifactForGradlePlugin(it, 'osx', 'x86_64')
200-
artifactForGradlePlugin(it, 'windows', 'x86_32')
201-
artifactForGradlePlugin(it, 'windows', 'x86_64')
202-
}
203-
}
204-
}
205-
206-
test {
207-
useJUnitPlatform()
208-
testLogging {
209-
showStandardStreams = true
210-
}
211-
}

compiler/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
gRPC Kotlin Codegen Plugin for Protobuf Compiler
2+
==============================================
3+
4+
This generates the Kotlin interfaces out of the service definition from a
5+
`.proto` file. It works with the Protobuf Compiler (`protoc`).
6+
7+
Normally you don't need to compile the codegen by yourself, since pre-compiled
8+
binaries for common platforms are available on Maven Central:
9+
10+
1. Navigate to https://mvnrepository.com/artifact/io.grpc/protoc-gen-grpc-kotlin
11+
2. Select a package version
12+
3. Click "Files: View All"
13+
14+
However, if the pre-compiled binaries are not compatible with your system,
15+
you may want to build your own codegen.
16+
17+
## System requirement
18+
19+
* Linux, Mac OS X with Clang, or Windows with MSYS2
20+
* Java 7 or up
21+
* [Protobuf](https://github.com/google/protobuf) 3.0.0-beta-3 or up
22+
23+
## Compiling and testing the codegen
24+
25+
Change to the `compiler` directory:
26+
27+
```
28+
$ cd $GRPC_KOTLIN_ROOT/compiler
29+
```
30+
31+
To compile the plugin:
32+
33+
```
34+
$ ../gradlew :protoc-gen-grpc-kotlin:build./gradlew
35+
```
36+
37+
To test the plugin with the compiler:
38+
39+
```
40+
$ ../gradlew test
41+
```
42+
43+
You will see a `PASS` if the test succeeds.
44+
45+
To compile a proto file and generate Kotlin interfaces out of the service definitions:
46+
47+
```
48+
$ protoc --plugin=protoc-gen-grpc-kotlin=build/install/protoc-gen-grpc-kotlin/bin/protoc-gen-grpc-kotlin \
49+
--grpckt_out="$OUTPUT_FILE" --proto_path="$DIR_OF_PROTO_FILE" "$PROTO_FILE"
50+
```
51+
52+
## Installing the codegen to Maven local repository
53+
54+
This will compile a codegen and put it under your `~/.m2/repository`. This
55+
will make it available to any build tool that pulls codegens from Maven
56+
repositories.
57+
58+
```
59+
$ ../gradlew publishToMavenLocal
60+
```

0 commit comments

Comments
 (0)