Skip to content

Commit

Permalink
Merge pull request #418 from onflow/m4ksio/pack-protobuf-into-jar
Browse files Browse the repository at this point in the history
Compile protobuf and release JAR
  • Loading branch information
m4ksio authored Mar 5, 2021
2 parents cbd894b + a478a0e commit 0373c51
Show file tree
Hide file tree
Showing 22 changed files with 153 additions and 11 deletions.
18 changes: 17 additions & 1 deletion protobuf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This folder contains the [Protocol Buffer](https://developers.google.com/protoco
Check out the [Flow Access API specification](/docs/content/access-api-spec.md).

## Generating stubs
## Generating Go stubs

You can use [prototool](https://github.com/uber/prototool) to generate gRPC client stubs in a variety of languages.

Expand All @@ -15,3 +15,19 @@ Running the command below (in the current directory) will generate stubs for Go:
```shell script
make generate
```

## Generating and publishing JVM stubs

JVM support is in the alpha stage; many steps require manual intervention.

`./gradlew generateProto` compiles Protobuf files into local Java classes.

### Publishing

`./gradlew publishToSonatype` prepares and publishes compiled classes into JAR and uploads to OSSRH staging repository.

This require signing artifacts which is done by [Signing Gradle plugin](https://docs.gradle.org/current/userguide/signing_plugin.html) - it requires
external configuration and appropriate GPG Keys. Please refer to plugin and [OSSRH](https://central.sonatype.org/pages/working-with-pgp-signatures.html)
documentation.
Uploading to staging repo requires an approved Sonatype account. Please refer to [Gradle Nexus Publish Plugin](https://github.com/gradle-nexus/publish-plugin)
documentation how to provide credentials.
10 changes: 0 additions & 10 deletions protobuf/build.gradle

This file was deleted.

108 changes: 108 additions & 0 deletions protobuf/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import com.google.protobuf.gradle.*


plugins {
id("com.google.protobuf") version "0.8.15"
`java-library`
`maven-publish`
signing
id("io.github.gradle-nexus.publish-plugin") version "1.0.0"
}

val protobufVersion = "3.14.0"
val grpcVersion = "1.35.0"

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:$protobufVersion"
}
plugins {
id("grpc") {
artifact = "io.grpc:protoc-gen-grpc-java:$grpcVersion"
}
}
generateProtoTasks {
all().forEach {
it.plugins {
id("grpc")
}
}
}
}

dependencies {
api("com.google.protobuf:protobuf-java:$protobufVersion")
api("io.grpc:grpc-netty-shaded:$grpcVersion")
api("io.grpc:grpc-protobuf:$grpcVersion")
api("io.grpc:grpc-stub:$grpcVersion")
api("javax.annotation:javax.annotation-api:1.3.2")
}

nexusPublishing {
repositories {
sonatype()
}
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])

pom {
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
name.set(project.name)
url.set("https://onflow.org")
description.set("The Flow Blockchain")
scm {
url.set("https://github.com/onflow/flow")
connection.set("scm:git:git@github.com/onflow/flow.git")
developerConnection.set("scm:git:git@github.com/onflow/flow.git")
}
developers {
developer {
name.set("Flow Developers")
url.set("https://onflow.org")
}
}
}
}
}
}

signing {
useGpgCmd() //use gpg2
sign(publishing.publications["mavenJava"])
}

sourceSets {
main {
proto {
// protobuf files must be defined in this dir, but using default filters
// will include build dir, so we override inclusion pattern while maintaining
// proto root dir
srcDirs("$projectDir/")
setIncludes(listOf("flow/**/*.proto"))
}
}
}

java {
withJavadocJar()
withSourcesJar()
}


repositories {
mavenCentral()
}

group = "org.onflow"

// TODO - grab version from Git
version = "0.20"
1 change: 1 addition & 0 deletions protobuf/flow/access/access.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package flow.access;

option go_package = "access";
option java_package = "org.onflow.protobuf.access";

import "flow/entities/account.proto";
import "flow/entities/block_header.proto";
Expand Down
1 change: 1 addition & 0 deletions protobuf/flow/entities/account.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package flow.entities;

option go_package = "entities";
option java_package = "org.onflow.protobuf.entities";

message Account {
bytes address = 1;
Expand Down
1 change: 1 addition & 0 deletions protobuf/flow/entities/block.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package flow.entities;

option go_package = "entities";
option java_package = "org.onflow.protobuf.entities";

import "google/protobuf/timestamp.proto";

Expand Down
1 change: 1 addition & 0 deletions protobuf/flow/entities/block_header.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package flow.entities;

option go_package = "entities";
option java_package = "org.onflow.protobuf.entities";

import "google/protobuf/timestamp.proto";

Expand Down
1 change: 1 addition & 0 deletions protobuf/flow/entities/block_seal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package flow.entities;

option go_package = "entities";
option java_package = "org.onflow.protobuf.entities";

message BlockSeal {
bytes block_id = 1;
Expand Down
1 change: 1 addition & 0 deletions protobuf/flow/entities/collection.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package flow.entities;

option go_package = "entities";
option java_package = "org.onflow.protobuf.entities";

message Collection {
bytes id = 1;
Expand Down
1 change: 1 addition & 0 deletions protobuf/flow/entities/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package flow.entities;

option go_package = "entities";
option java_package = "org.onflow.protobuf.entities";

message Event {
string type = 1;
Expand Down
1 change: 1 addition & 0 deletions protobuf/flow/entities/transaction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package flow.entities;

option go_package = "entities";
option java_package = "org.onflow.protobuf.entities";

enum TransactionStatus {
UNKNOWN = 0;
Expand Down
1 change: 1 addition & 0 deletions protobuf/flow/execution/execution.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package flow.execution;

option go_package = "execution";
option java_package = "org.onflow.protobuf.execution";

import "flow/entities/account.proto";
import "flow/entities/event.proto";
Expand Down
2 changes: 2 additions & 0 deletions protobuf/flow/legacy/access/access.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package access;

option java_package = "org.onflow.protobuf.legacy.access";

import "flow/legacy/entities/account.proto";
import "flow/legacy/entities/block_header.proto";
import "flow/legacy/entities/block.proto";
Expand Down
2 changes: 2 additions & 0 deletions protobuf/flow/legacy/entities/account.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package entities;

option java_package = "org.onflow.protobuf.legacy.entities";

message Account {
bytes address = 1;
uint64 balance = 2;
Expand Down
2 changes: 2 additions & 0 deletions protobuf/flow/legacy/entities/block.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package entities;

option java_package = "org.onflow.protobuf.legacy.entities";

import "google/protobuf/timestamp.proto";

import "flow/legacy/entities/collection.proto";
Expand Down
2 changes: 2 additions & 0 deletions protobuf/flow/legacy/entities/block_header.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package entities;

option java_package = "org.onflow.protobuf.legacy.entities";

import "google/protobuf/timestamp.proto";

message BlockHeader {
Expand Down
2 changes: 2 additions & 0 deletions protobuf/flow/legacy/entities/block_seal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package entities;

option java_package = "org.onflow.protobuf.legacy.entities";

message BlockSeal {
bytes block_id = 1;
bytes execution_receipt_id = 2;
Expand Down
2 changes: 2 additions & 0 deletions protobuf/flow/legacy/entities/collection.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package entities;

option java_package = "org.onflow.protobuf.legacy.entities";

message Collection {
bytes id = 1;
repeated bytes transaction_ids = 2;
Expand Down
2 changes: 2 additions & 0 deletions protobuf/flow/legacy/entities/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package entities;

option java_package = "org.onflow.protobuf.legacy.entities";

message Event {
string type = 1;
bytes transaction_id = 2;
Expand Down
2 changes: 2 additions & 0 deletions protobuf/flow/legacy/entities/transaction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package entities;

option java_package = "org.onflow.protobuf.legacy.entities";

enum TransactionStatus {
UNKNOWN = 0;
PENDING = 1;
Expand Down
2 changes: 2 additions & 0 deletions protobuf/flow/legacy/execution/execution.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package execution;

option java_package = "org.onflow.protobuf.legacy.execution";

import "flow/legacy/entities/account.proto";
import "flow/legacy/entities/event.proto";

Expand Down
1 change: 1 addition & 0 deletions protobuf/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name="flow"

1 comment on commit 0373c51

@vercel
Copy link

@vercel vercel bot commented on 0373c51 Mar 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.