Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
497 views
in Technique[技术] by (71.8m points)

java - "Could not resolve com.google.protobuf:protoc:4.0.0-rc-2" trying to use the Protobuf Gradle plugin

I'm trying to follow along this blog post, https://redbyte.eu/en/blog/calling-java-from-go-using-grpc/, with a working example for which my initial attempt is in this repository, https://github.com/khpeek/pdf-parser. The project has the following structure:

.
├── build
│?? ├── extracted-include-protos
│?? │?? └── main
│?? ├── extracted-protos
│?? │?? └── main
│?? └── tmp
│??     └── jar
│??         └── MANIFEST.MF
├── build.gradle
├── gradle
│?? └── wrapper
│??     ├── gradle-wrapper.jar
│??     └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
    └── main
        └── proto
            └── pdfparserapi.proto

where the build.gradle is as follows:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.14'
    }
}

plugins {
    id "com.google.protobuf" version "0.8.14"
    id "java"
}

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:4.0.0-rc-2'
    }
    plugins {
        grpc {
            artifact = 'io.grpc:protoc-gen-grpc-java:1.14.0'
        }
    }
    generateProtoTasks {
        all()*.plugins { grpc {} }
    }
}

However, I if I run ./gradlew build, I get the following error:

> ./gradlew build
> Task :generateProto FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':generateProto'.
> Could not resolve all files for configuration ':protobufToolsLocator_protoc'.
   > Could not resolve com.google.protobuf:protoc:4.0.0-rc-2.
     Required by:
         project :
      > Could not resolve com.google.protobuf:protoc:4.0.0-rc-2.
         > Could not get resource 'https://artifacts.apple.com/libs-release/com/google/protobuf/protoc/4.0.0-rc-2/protoc-4.0.0-rc-2.pom'.
            > Could not GET 'https://artifacts.apple.com/libs-release/com/google/protobuf/protoc/4.0.0-rc-2/protoc-4.0.0-rc-2.pom'.
               > artifacts.apple.com
      > Could not resolve com.google.protobuf:protoc:4.0.0-rc-2.
         > Could not get resource 'https://artifacts.apple.com/libs-snapshot/com/google/protobuf/protoc/4.0.0-rc-2/protoc-4.0.0-rc-2.pom'.
            > Could not GET 'https://artifacts.apple.com/libs-snapshot/com/google/protobuf/protoc/4.0.0-rc-2/protoc-4.0.0-rc-2.pom'.
               > artifacts.apple.com

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 908ms
3 actionable tasks: 3 executed

I'm not sure what causes this error because I can find that version of the dependency on Maven Central (https://search.maven.org/artifact/com.google.protobuf/protoc/4.0.0-rc-2/pom). Any idea how to resolve this issue?

(One thing that I observed that could be related is that the grpc closure is grayed out and if I hover over it in IntelliJ, I see the message

No candidates found for method call grpc.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have not defined any repositories where Gradle can retrieve dependencies.

See https://docs.gradle.org/current/userguide/declaring_repositories.html

Adding the following will fix the dependency retrieval issue:

repositories {
    mavenCentral()
}

(One thing that I observed that could be related is that the grpc closure is grayed out and if I hover over it in IntelliJ, I see the message

This is a limitation of the Groovy DSL which is the default DSL for Gradle files (*.gradle files). IntelliJ is able to infer some types, but not all. If you want full/complete code completion and strong intelliSense, then switch to the Kotlin DSL.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...