Skip to content

Commit

Permalink
Use Gradle Plugin to generate proto files automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
hb0 committed May 26, 2021
1 parent ba70b89 commit 43acf08
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ gradle.properties
**/secrets
*.json

# Generated java classes from proto files
src/main/java/

# Temporary Git Files
**/*.orig

Expand Down
6 changes: 6 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ However, the pre-compiled `JARs` are also published to the link:https://github.c
- how to use with link:https://github.com/protocolbuffers/protobuf/tree/master/java#gradle[Gradle]
- how to use with link:https://github.com/protocolbuffers/protobuf/tree/master/java#use-java-protocol-buffers-on-android[Android]

Instead of using the pre-compiled `java` classes (published `JAR`s) it's recommended to use `javalite` for Android. These classes can either be manually generated with:

protoc --java_out=lite:./src/main/java/ src/main/protos/de/cyface/protos/model/measurement.proto

Or you can download the `proto` link:protoc --java_out=./src/main/java/ src/main/protos/de/cyface/protos/model/measurement.proto[files] from this repository and then generate the classes using the link:https://github.com/google/protobuf-gradle-plugin[Gradle Plugin]. This is done in the link:https://github.com/cyface-de/android-backend[Cyface Android SDK] - check it out if you need an example.

The serializers encode the data in an efficient way, the decision process is documented link:https://cyface.atlassian.net/wiki/spaces/IM/pages/1535148033/Datenformat+bertragungsprotokoll+2021[internally].


Expand Down
20 changes: 18 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ plugins {
id 'maven-publish'
//noinspection SpellCheckingInspection
id 'com.github.johnrengelman.shadow' version '6.1.0'
id 'com.google.protobuf' version '0.8.16'
}

group = 'de.cyface'
Expand Down Expand Up @@ -69,7 +70,7 @@ repositories {

// Code Quality Checker
dependencies {
// Protobuf generated java files
// Generate java files from the Protobuf files
implementation "com.google.protobuf:protobuf-java:$protobufVersion"

// Utility
Expand All @@ -85,6 +86,21 @@ dependencies {
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
}

// See https://github.com/google/protobuf-gradle-plugin
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:$protobufVersion"
}
generateProtoTasks {
//noinspection GroovyAssignabilityCheck
all().each { task ->
task.builtins {
java {}
}
}
}
}

test {
useJUnitPlatform()
testLogging {
Expand Down Expand Up @@ -113,7 +129,7 @@ publishing {
publications {
//noinspection GroovyAssignabilityCheck
publishExecutable(MavenPublication) {
//noinspection GroovyAssignabilityCheckssssssss
//noinspection GroovyAssignabilityCheck
from components.java
}
}
Expand Down

0 comments on commit 43acf08

Please sign in to comment.