【问题标题】:Unable to access generated java files无法访问生成的 java 文件
【发布时间】:2017-07-16 06:40:00
【问题描述】:

我的项目使用 gRPC,它会在生成的文件夹中生成一个文件。

这是我的 build.gradle 模块。

apply plugin: 'java'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'io.grpc:grpc-okhttp:1.4.0'
    compile 'io.grpc:grpc-protobuf-lite:1.4.0'
    compile 'io.grpc:grpc-stub:1.4.0'
    compile 'javax.annotation:javax.annotation-api:1.2'
}

sourceCompatibility = "1.7"
targetCompatibility = "1.7"


apply plugin: 'com.google.protobuf'
def grpcVersion = '1.4.0' // CURRENT_GRPC_VERSION
protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.3.0'
    }
    plugins {
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
        }
    }
    generateProtoTasks {
        all()*.plugins {
            grpc {
                // To generate deprecated interfaces and static bindService method,
                // turn the enable_deprecated option to true below:
                option 'enable_deprecated=false'
            }
        }
    }
}


// Inform IntelliJ projects about the generated code.
apply plugin: 'idea'

idea {
    module {
        // Not using generatedSourceDirs because of
        // https://discuss.gradle.org/t/support-for-intellij-2016/15294/8
        sourceDirs += file("${projectDir}/build/generated/source/proto/main/java");
        sourceDirs += file("${projectDir}/build/generated/source/proto/main/grpc");
    }
}

我该如何解决这个问题?

【问题讨论】:

    标签: java android-studio gradle grpc


    【解决方案1】:

    您必须将此文件夹添加到您的源集。 以下应该有效:

    sourceSets {
       generated{
            java.srcDir "${projectDir}/build/generated/source/proto/main/java"
       }
    }
    

    Here 是用于自定义源集的综合文档。

    【讨论】:

    • 你的回答启发了我。非常感谢。
    • @LoveRight,没问题,欢迎采纳。
    【解决方案2】:

    我想通了。我的 iml 文件包含该文件夹,但也排除了它。我认为排除优先,所以我必须删除 <excludeFolder> 元素。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多