“无法解析com.googleprotobuf:protoc:4.0.0-rc-2“尝试使用protobuf gradle插件

dluptydi  于 2021-06-26  发布在  Java
关注(0)|答案(1)|浏览(633)

我试着跟着这篇博文,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的候选对象。

kadbb459

kadbb4591#

您尚未定义gradle可以检索依赖项的任何存储库。
看到了吗https://docs.gradle.org/current/userguide/declaring_repositories.html
添加以下内容将修复依赖项检索问题:

repositories {
    mavenCentral()
}

(我观察到的一件事可能与此有关,那就是grpc闭包是灰色的,如果我在intellij中将鼠标悬停在它上面,我会看到消息
这是groovy dsl的一个限制,groovy dsl是gradle文件的默认dsl( *.gradle 文件)。intellij能够推断出一些类型,但不是全部。如果您想要完整/完整的代码完成和强大的智能感知,那么切换到kotlin dsl。

相关问题