2017-07-16 105 views
0

我的项目使用gRPC并在生成的文件夹中生成一个文件。无法访问生成的java文件

enter image description here

这是我模块的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"); 
    } 
} 

我该如何解决这个问题?

回答

2

您必须将此文件夹添加到您的源集。 下面应该工作:

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

Here是自定义源设置一个全面的文档。

+0

您的回答启发了我。非常感谢。 – Gqqnbig

+0

@LoveRight,没问题,欢迎您接受。 – meltedspark

0

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

enter image description here