plugins { id 'java-library' id 'com.google.protobuf' id 'maven-publish' } dependencies { api "com.google.protobuf:protobuf-java-util:${protobufVersion}" api "com.google.protobuf:protobuf-java:${protobufVersion}" api "io.grpc:grpc-protobuf:${grpcVersion}" api "io.grpc:grpc-stub:${grpcVersion}" implementation "com.google.guava:guava:${guavaVersion}" implementation "io.grpc:grpc-netty-shaded:${grpcVersion}" compileOnly 'javax.annotation:javax.annotation-api:1.3.2' testImplementation "com.google.code.gson:gson:${gsonVersion}" testImplementation "io.grpc:grpc-inprocess:${grpcVersion}" testImplementation "io.grpc:grpc-testing:${grpcVersion}" } sourceSets { main { proto { srcDir rootProject.file('../../src/ZB.MOM.WW.MxGateway.Contracts/Protos') include 'mxaccess_gateway.proto' include 'mxaccess_worker.proto' include 'galaxy_repository.proto' } } } java { withSourcesJar() withJavadocJar() } protobuf { protoc { artifact = "com.google.protobuf:protoc:${protobufVersion}" } plugins { grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" } } generatedFilesBaseDir = rootProject.file('src/main/generated').absolutePath generateProtoTasks { all().configureEach { plugins { grpc {} } } } } // IPC-09 guard: the generated Java tree is tracked (generatedFilesBaseDir above points at the // committed src/main/generated). `gradle build` regenerates it, so an un-regenerated .proto change, // or a plugin/protobuf version bump, silently drifts the committed output. checkGeneratedClean // fails when the regenerated tree differs from what is committed. // // Caveat (repo memory project_java_generated_churn): the protobuf gradle plugin also rewrites // MxaccessGateway.java with a spurious protobuf-runtime-version delta on every build even when no // .proto changed. CI reverts that one file (git checkout) before invoking this task; locally, do the // same when you did not touch a .proto. See docs/GatewayTesting.md "Continuous Integration". tasks.register('checkGeneratedClean') { group = 'verification' description = 'Fails if the committed generated Java tree differs from a fresh regeneration.' dependsOn 'generateProto' doLast { def generatedDir = 'clients/java/src/main/generated' def stdout = new ByteArrayOutputStream() def result = exec { workingDir = rootProject.projectDir.parentFile.parentFile commandLine 'git', 'status', '--porcelain', '--', generatedDir standardOutput = stdout ignoreExitValue = true } def dirty = stdout.toString().trim() if (!dirty.isEmpty()) { throw new GradleException( "Generated Java is stale or churned:\n${dirty}\n" + "Regenerate and commit after a .proto change, or 'git checkout' the spurious " + "MxaccessGateway.java protobuf-version churn when no .proto changed.") } } }