简体   繁体   中英

“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 .

在此处输入图像描述

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM