【问题标题】:"Could not resolve com.google.protobuf:protoc:4.0.0-rc-2" trying to use the Protobuf Gradle plugin“无法解析 com.google.protobuf:protoc:4.0.0-rc-2”尝试使用 Protobuf Gradle 插件
【发布时间】:2021-01-08 18:20:44
【问题描述】:

我正在尝试关注这篇博文https://redbyte.eu/en/blog/calling-java-from-go-using-grpc/,并提供一个我最初尝试在此存储库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 中将鼠标悬停在它上面,我会看到消息

没有找到方法调用grpc的候选者。

【问题讨论】:

    标签: java gradle protocol-buffers proto


    【解决方案1】:

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

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

    添加以下内容将修复依赖项检索问题:

    repositories {
        mavenCentral()
    }
    

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

    这是 Groovy DSL 的一个限制,它是 Gradle 文件(*.gradle 文件)的默认 DSL。 IntelliJ 能够推断出 一些 类型,但不是全部。如果你想要完整/完整的代码补全强大的intelliSense,然后切换到Kotlin DSL

    【讨论】:

      猜你喜欢
      • 2022-06-21
      • 1970-01-01
      • 2017-09-26
      • 2022-12-21
      • 2016-02-08
      • 2017-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多