salesforce / reactive-grpc

Reactive stubs for gRPC
BSD 3-Clause "New" or "Revised" License
832 stars 118 forks source link

Need help in using reactor-grpc with gradle in windows #182

Closed anandps closed 5 years ago

anandps commented 5 years ago

reactor-grpc with gradle not working in windows when executed using Gitbash. protoc errors out with "%1 is not a valid Win32 application.". build.gradle

buildscript {
    repositories {
        maven { // The google mirror is less flaky than mavenCentral()
        url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
    }
    dependencies {
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10'
    }
}

plugins {
    // ASSUMES GRADLE 2.12 OR HIGHER. Use plugin version 0.7.5 with earlier gradle versions
    id 'idea'
    id 'com.google.protobuf' version '0.8.10'
}

group 'com.salesforce.servicelibs'
version '0.10.0'

def grpcVersion = '1.21.0' // CURRENT_GRPC_VERSION
def protobufVersion = '3.7.1'
def protocVersion = protobufVersion
def reactiveGrpcVersion = '0.10.0'

dependencies {

    //gRPC dependencies
    implementation "io.grpc:grpc-protobuf:${grpcVersion}"
    implementation "io.grpc:grpc-stub:${grpcVersion}"
    compileOnly "javax.annotation:javax.annotation-api:1.2"

    //reactive-gRPC
    implementation "com.salesforce.servicelibs:grpc-spring:0.8.0"
    implementation "com.salesforce.servicelibs:reactor-grpc-stub:${reactiveGrpcVersion}"

    // examples/advanced need this for JsonFormat
    implementation "com.google.protobuf:protobuf-java-util:${protobufVersion}"

    runtimeOnly "io.grpc:grpc-netty-shaded:${grpcVersion}"

    testImplementation "io.grpc:grpc-testing:${grpcVersion}"
    testImplementation "junit:junit:4.12"
    testImplementation "org.mockito:mockito-core:2.25.1"
}

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:${protocVersion}"
    }
    clean {
        delete protobuf.generatedFilesBaseDir
    }
    plugins {
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
        }
        reactor {
            artifact = "com.salesforce.servicelibs:reactor-grpc:${reactiveGrpcVersion}:jdk8@jar"
        }
    }
    generateProtoTasks {
        ofSourceSet('main')*.plugins {
            grpc {}
            reactor {}
        }
    }
}

// Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code.
sourceSets.main.java.srcDir new File(buildDir, 'generated/source/proto/main/grpc')
sourceSets.main.java.srcDir new File(buildDir, 'generated/source/proto/main/reactor')
sourceSets.main.java.srcDir new File(buildDir, 'generated/source/proto/main/java')
idea {
    module {
        generatedSourceDirs += file("build/generated/source/proto/main/grpc")
        generatedSourceDirs += file("build/generated/source/proto/main/reactor")
        generatedSourceDirs += file("build/generated/source/proto/main/java")
    }
}

Error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':reactive-grpc-example:generateProto'.
> protoc: stdout: . stderr: --reactor_out: protoc-gen-reactor: %1 is not a valid Win32 application.
rmichela commented 5 years ago

Unfortunately, "at this time, Reactor-gRPC with Gradle only supports bash-based environments. Windows users will need to build using Windows Subsystem for Linux (win 10), Gitbash, or Cygwin." https://github.com/salesforce/reactive-grpc/tree/master/reactor#gradle

This limitation is due to how protobuf-gradle-plugin handles (or doesn't handle) java plugins. https://github.com/google/protobuf-gradle-plugin/issues/31

anandps commented 5 years ago

Thanks for your response! Yes, i am using the Gitbash. Perhaps it works only for the linux subsystem?(Doc mentioned Gitbash & cygwin)

rmichela commented 5 years ago

Hmm... Try WSL. I don't have a Windows machine to test.

cbornet commented 5 years ago

As a workaround you can call the maven plugin from a Gradle task.

rmichela commented 5 years ago

Were you able to get the gradle->maven or WSL workaround working, @anandps?

anandps commented 5 years ago

yes, tried both. WSL works fine and for gradle->maven workaround, followed this https://github.com/cbornet/generator-jhipster-grpc/blob/v0.14.1/generators/app/templates/_grpc.gradle. I see that the doc is already updated with "Windows users will need to build using Windows Subsystem for Linux (win 10) or invoke the Maven protobuf plugin with Gradle." :)

rmichela commented 5 years ago

I'm working on a more complete solution: https://github.com/salesforce/grpc-java-contrib/pull/115

Canteen will let me package jars as self executing executables for each platform. Reactive-gRPC 1.0.0 will have native support for Windows+Gradle #186

rmichela commented 5 years ago

1.0.0 is now out. To use it, remove the jdk8@jar from the gradle reference.