From 0581d1c3fe7199e7eeda8f365daddc536a61bc51 Mon Sep 17 00:00:00 2001 From: Chengyuan Zhang Date: Fri, 5 Mar 2021 01:20:07 -0800 Subject: [PATCH] Do not create the outputSubDir leaf if its name ends with .jar or .zip to support outputting directly into an archive. --- .../com/google/protobuf/gradle/GenerateProtoTask.groovy | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy index 97a94eb8..3561e5ae 100644 --- a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy @@ -555,7 +555,13 @@ public abstract class GenerateProtoTask extends DefaultTask { List protoFiles = sourceFiles.files.sort() [builtins, plugins]*.each { plugin -> - File outputDir = new File(getOutputDir(plugin)) + String outputPath = getOutputDir(plugin) + File outputDir = new File(outputPath) + // protoc is capable of output generated files directly to a JAR file + // or ZIP archive if the output location ends with .jar/.zip + if (outputPath.endsWith(".jar") || outputPath.endsWith(".zip")) { + outputDir = outputDir.getParentFile() + } outputDir.mkdirs() }