"Could not resolve com.google.protobuf:protoc:4.0.0-rc-2" 尝试使用 Protobuf Gradle 插件

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

我正在尝试关注此博客 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。该项目具有以下结构:

.
├── 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

其中build.gradle如下:

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 {} }
    }
}

但是,如果我 运行 ./gradlew build,我会得到以下错误:

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

我不确定是什么原因导致此错误,因为我可以在 Maven Central (https://search.maven.org/artifact/com.google.protobuf/protoc/4.0.0-rc-2/pom) 上找到该版本的依赖项。知道如何解决这个问题吗?

(我观察到的可能相关的一件事是 grpc 闭包显示为灰色,如果我在 IntelliJ 中将鼠标悬停在它上面,我会看到消息

No candidates found for method call grpc.

您尚未定义任何 Gradle 可以检索依赖项的存储库。

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

添加以下内容将解决依赖项检索问题:

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

这是 Groovy DSL 的限制,它是 Gradle 文件(*.gradle 文件)的默认 DSL。 IntelliJ 能够推断出 一些 类型,但不是全部。如果你想要 full/complete 代码补全 and strong intelliSense, then switch to the Kotlin DSL.