diff --git a/protobuf/README.md b/protobuf/README.md index 314e8797f..ee4f01855 100644 --- a/protobuf/README.md +++ b/protobuf/README.md @@ -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. @@ -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. diff --git a/protobuf/build.gradle b/protobuf/build.gradle deleted file mode 100644 index 511c4cf8c..000000000 --- a/protobuf/build.gradle +++ /dev/null @@ -1,10 +0,0 @@ -apply plugin: 'java' -apply plugin: 'maven' - -jar { - from("flow") { - into "proto/" - } -} - -group = 'org.onflow.flow-jvm' diff --git a/protobuf/build.gradle.kts b/protobuf/build.gradle.kts new file mode 100644 index 000000000..9e98f8e3f --- /dev/null +++ b/protobuf/build.gradle.kts @@ -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("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" diff --git a/protobuf/flow/access/access.proto b/protobuf/flow/access/access.proto index 6692677db..51ea1acfa 100644 --- a/protobuf/flow/access/access.proto +++ b/protobuf/flow/access/access.proto @@ -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"; diff --git a/protobuf/flow/entities/account.proto b/protobuf/flow/entities/account.proto index 30926de91..272be2905 100644 --- a/protobuf/flow/entities/account.proto +++ b/protobuf/flow/entities/account.proto @@ -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; diff --git a/protobuf/flow/entities/block.proto b/protobuf/flow/entities/block.proto index 43b8221a7..43124c354 100644 --- a/protobuf/flow/entities/block.proto +++ b/protobuf/flow/entities/block.proto @@ -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"; diff --git a/protobuf/flow/entities/block_header.proto b/protobuf/flow/entities/block_header.proto index 153916a92..80dedb81f 100644 --- a/protobuf/flow/entities/block_header.proto +++ b/protobuf/flow/entities/block_header.proto @@ -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"; diff --git a/protobuf/flow/entities/block_seal.proto b/protobuf/flow/entities/block_seal.proto index c306c784f..0c19f8c53 100644 --- a/protobuf/flow/entities/block_seal.proto +++ b/protobuf/flow/entities/block_seal.proto @@ -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; diff --git a/protobuf/flow/entities/collection.proto b/protobuf/flow/entities/collection.proto index 7aded5193..dfc615e68 100644 --- a/protobuf/flow/entities/collection.proto +++ b/protobuf/flow/entities/collection.proto @@ -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; diff --git a/protobuf/flow/entities/event.proto b/protobuf/flow/entities/event.proto index 9ceefa3cc..773881263 100644 --- a/protobuf/flow/entities/event.proto +++ b/protobuf/flow/entities/event.proto @@ -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; diff --git a/protobuf/flow/entities/transaction.proto b/protobuf/flow/entities/transaction.proto index 93edb0ba6..81a19c3e7 100644 --- a/protobuf/flow/entities/transaction.proto +++ b/protobuf/flow/entities/transaction.proto @@ -3,6 +3,7 @@ syntax = "proto3"; package flow.entities; option go_package = "entities"; +option java_package = "org.onflow.protobuf.entities"; enum TransactionStatus { UNKNOWN = 0; diff --git a/protobuf/flow/execution/execution.proto b/protobuf/flow/execution/execution.proto index 6f8be2f48..5f8ddad9b 100644 --- a/protobuf/flow/execution/execution.proto +++ b/protobuf/flow/execution/execution.proto @@ -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"; diff --git a/protobuf/flow/legacy/access/access.proto b/protobuf/flow/legacy/access/access.proto index 9aa9e081c..d3beb5468 100644 --- a/protobuf/flow/legacy/access/access.proto +++ b/protobuf/flow/legacy/access/access.proto @@ -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"; diff --git a/protobuf/flow/legacy/entities/account.proto b/protobuf/flow/legacy/entities/account.proto index 730b37d19..25a4bc59b 100644 --- a/protobuf/flow/legacy/entities/account.proto +++ b/protobuf/flow/legacy/entities/account.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package entities; +option java_package = "org.onflow.protobuf.legacy.entities"; + message Account { bytes address = 1; uint64 balance = 2; diff --git a/protobuf/flow/legacy/entities/block.proto b/protobuf/flow/legacy/entities/block.proto index e36dd88a6..8104a42b7 100644 --- a/protobuf/flow/legacy/entities/block.proto +++ b/protobuf/flow/legacy/entities/block.proto @@ -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"; diff --git a/protobuf/flow/legacy/entities/block_header.proto b/protobuf/flow/legacy/entities/block_header.proto index 38c8afb18..d7af19043 100644 --- a/protobuf/flow/legacy/entities/block_header.proto +++ b/protobuf/flow/legacy/entities/block_header.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package entities; +option java_package = "org.onflow.protobuf.legacy.entities"; + import "google/protobuf/timestamp.proto"; message BlockHeader { diff --git a/protobuf/flow/legacy/entities/block_seal.proto b/protobuf/flow/legacy/entities/block_seal.proto index 6989735b4..2c5e3bb8f 100644 --- a/protobuf/flow/legacy/entities/block_seal.proto +++ b/protobuf/flow/legacy/entities/block_seal.proto @@ -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; diff --git a/protobuf/flow/legacy/entities/collection.proto b/protobuf/flow/legacy/entities/collection.proto index 3bb9bba0e..08b28cf2a 100644 --- a/protobuf/flow/legacy/entities/collection.proto +++ b/protobuf/flow/legacy/entities/collection.proto @@ -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; diff --git a/protobuf/flow/legacy/entities/event.proto b/protobuf/flow/legacy/entities/event.proto index 7283a1822..7d7733288 100644 --- a/protobuf/flow/legacy/entities/event.proto +++ b/protobuf/flow/legacy/entities/event.proto @@ -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; diff --git a/protobuf/flow/legacy/entities/transaction.proto b/protobuf/flow/legacy/entities/transaction.proto index 11e4d85a7..fdc086c42 100644 --- a/protobuf/flow/legacy/entities/transaction.proto +++ b/protobuf/flow/legacy/entities/transaction.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package entities; +option java_package = "org.onflow.protobuf.legacy.entities"; + enum TransactionStatus { UNKNOWN = 0; PENDING = 1; diff --git a/protobuf/flow/legacy/execution/execution.proto b/protobuf/flow/legacy/execution/execution.proto index f12db6af4..320500795 100644 --- a/protobuf/flow/legacy/execution/execution.proto +++ b/protobuf/flow/legacy/execution/execution.proto @@ -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"; diff --git a/protobuf/settings.gradle.kts b/protobuf/settings.gradle.kts new file mode 100644 index 000000000..cc37a49dc --- /dev/null +++ b/protobuf/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name="flow"