11plugins {
22 id ' java'
33 id ' java-library-distribution'
4- id ' com.google.protobuf' version ' 0.9.1 '
4+ id ' com.google.protobuf' version ' 0.9.4 '
55}
66
77dependencies {
@@ -20,16 +20,40 @@ protobuf {
2020 generateProtoTasks {
2121 all()* . plugins { grpc {} }
2222 }
23- generatedFilesBaseDir = " $projectDir /src"
2423}
2524
26- archivesBaseName = " sample-rpc"
25+ base {
26+ archivesName = " sample-rpc"
27+ }
28+
29+ // Task copyGeneratedProtoToSrc copies the generated .java files into src directory
30+ task copyGeneratedProtoToSrc (type : Copy ) {
31+ description ' Copies generated Protocol Buffer classes to src/main/java/sample/rpc'
32+ dependsOn generateProto
33+ from " $buildDir /generated/source/proto/main/java/sample/rpc"
34+ into " $projectDir /src/main/java/sample/rpc"
35+ duplicatesStrategy = DuplicatesStrategy . INCLUDE
36+ }
37+
38+ // Task deleteBuildMainJava deletes the generated .java files in build directory
39+ task deleteBuildMainJava (type : Delete ) {
40+ dependsOn copyGeneratedProtoToSrc
41+ delete fileTree(dir : " $buildDir /generated/source/proto/main/java/sample/rpc" )
42+ }
2743
2844// The processResources task needs to depend on the generateProto task because it uses the output
2945// of the the generateProto task
3046processResources {
3147 dependsOn generateProto
3248}
3349
34- sourceCompatibility = 1.8
35- targetCompatibility = 1.8
50+ // Task deleteBuildMainJava needs to depend on deleteBuildMainJava to avoid duplicate class error
51+ tasks. named(" compileJava" ). configure {
52+ dependsOn deleteBuildMainJava
53+ }
54+
55+ java {
56+ toolchain {
57+ languageVersion = JavaLanguageVersion . of(8 )
58+ }
59+ }
0 commit comments