From 568d25dae9af7d3f24f5b423fb6589559f30740c Mon Sep 17 00:00:00 2001 From: Kun Zhang Date: Fri, 15 May 2015 10:37:57 -0700 Subject: [PATCH] Delete the generated files only before generateProto. Previously generated files were deleted at configuration time. Running non-build tasks such as ``clean`` or ``tasks`` would delete the generated files and tracked by git, which is annoying. Now we delete them only before the ``generateProto`` task, which solves the problem. After this change, the case that ``generateProto`` is not executed at all, is no longer covered. However, it is much less likely than the still-covered case that ``generateProto`` is not re-generating all files due to misconfiguration. --- build.gradle | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index f3ce21adbc..6d2289afa9 100644 --- a/build.gradle +++ b/build.gradle @@ -58,16 +58,19 @@ subprojects { project.protocDep = "com.google.protobuf:protoc:${protobufVersion}" } project.generatedFileDir = "${projectDir}/src/generated" + task deleteGeneratedSource << { + project.delete project.fileTree(dir: generatedSourcePath) + } project.afterEvaluate { generateProto.dependsOn ':grpc-compiler:java_pluginExecutable' + // Delete the generated sources first, so that we can be alerted if they are not re-compiled. + generateProto.dependsOn deleteGeneratedSource // Recompile protos when the codegen has been changed generateProto.inputs.file javaPluginPath // Recompile protos when build.gradle has been changed, because // it's possible the version of protoc has been changed. generateProto.inputs.file "${rootProject.projectDir}/build.gradle" } - // Delete the generated sources first, so that we can be alerted if they are not re-compiled. - project.delete project.fileTree(dir: generatedSourcePath) project.sourceSets { main {