Skip to content

Commit 568d25d

Browse files
committed
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.
1 parent 2a58bf8 commit 568d25d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,19 @@ subprojects {
5858
project.protocDep = "com.google.protobuf:protoc:${protobufVersion}"
5959
}
6060
project.generatedFileDir = "${projectDir}/src/generated"
61+
task deleteGeneratedSource << {
62+
project.delete project.fileTree(dir: generatedSourcePath)
63+
}
6164
project.afterEvaluate {
6265
generateProto.dependsOn ':grpc-compiler:java_pluginExecutable'
66+
// Delete the generated sources first, so that we can be alerted if they are not re-compiled.
67+
generateProto.dependsOn deleteGeneratedSource
6368
// Recompile protos when the codegen has been changed
6469
generateProto.inputs.file javaPluginPath
6570
// Recompile protos when build.gradle has been changed, because
6671
// it's possible the version of protoc has been changed.
6772
generateProto.inputs.file "${rootProject.projectDir}/build.gradle"
6873
}
69-
// Delete the generated sources first, so that we can be alerted if they are not re-compiled.
70-
project.delete project.fileTree(dir: generatedSourcePath)
7174

7275
project.sourceSets {
7376
main {

0 commit comments

Comments
 (0)