【问题标题】:Eclipse not showing generateProto task under a gradle projectEclipse 未在 gradle 项目下显示 generateProto 任务
【发布时间】:2018-07-29 13:55:23
【问题描述】:

我正在开发一个基于 GRPC 的项目,并且正在使用 gradle 来获取所有依赖项并从我的 proto 文件生成 java 文件。

这是我的build.gradle 文件,

apply plugin: 'java-library'
apply plugin: 'java'
apply plugin: 'com.google.protobuf'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use mavenCentral for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    mavenCentral()
}

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    // ASSUMES GRADLE 2.12 OR HIGHER. Use plugin version 0.7.5 with earlier
    // gradle versions
    classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.5'
  }
}

dependencies {
    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:23.0'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'

    //grpc
    compile 'io.grpc:grpc-netty:1.13.1'
    compile 'io.grpc:grpc-protobuf:1.13.1'
    compile 'io.grpc:grpc-stub:1.13.1'
}

protobuf {
  protoc {
    artifact = "com.google.protobuf:protoc:3.5.1-1"
  }
  plugins {
    grpc {
      artifact = 'io.grpc:protoc-gen-grpc-java:1.13.1'
    }
  }
  generateProtoTasks {
    all()*.plugins {
      grpc {}
    }
  }
}

刷新 gradle 项目后,我在 eclipse 的 gradle 任务下看不到 generateProto。我选择了eclipse下的Gradle项目来创建我的项目。

【问题讨论】:

    标签: eclipse gradle build.gradle protocol-buffers grpc


    【解决方案1】:

    他们没有出现的原因可以在here找到。

    基本上generate{*}Prooto 任务没有组名,因此eclipse Gradle 任务视图不会显示它们。你可以给他们添加一个组名,然后他们就会出现。

    protobuf {
      generateProtoTasks {
        all().each {
          it.group = 'my gen proto group'
        }
      }
    }
    

    【讨论】:

    • 在构建项目后,我只是简单地在 main/proto/simple.proto 中创建了 Gradle 项目和 .proto 文件,我可以在 build/ 文件夹中看到生成的代码,但是当我试图从我的主类中访问它,然后 eclipse 找不到那个原型消息类。有什么想法请帮忙。
    • @Az.MaYo 我在同一条船上......我们如何让 Eclipse 将生成的 Java 类视为资源
    • 我从 eclipse 转到了 intellij Idea。相同的代码工作正常。
    猜你喜欢
    • 2017-07-28
    • 1970-01-01
    • 2016-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    • 2011-04-15
    • 1970-01-01
    相关资源
    最近更新 更多