Skip to content

Commit cd45c9d

Browse files
authored
Support outputting generated code directly into JAR/ZIP archives (#480)
Do not create the outputSubDir's leaf as a directory if its name ends with .jar or .zip. This allows output generated code directly into an archive.
1 parent 0500ff3 commit cd45c9d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy

+7-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,13 @@ public abstract class GenerateProtoTask extends DefaultTask {
555555
List<File> protoFiles = sourceFiles.files.sort()
556556

557557
[builtins, plugins]*.each { plugin ->
558-
File outputDir = new File(getOutputDir(plugin))
558+
String outputPath = getOutputDir(plugin)
559+
File outputDir = new File(outputPath)
560+
// protoc is capable of output generated files directly to a JAR file
561+
// or ZIP archive if the output location ends with .jar/.zip
562+
if (outputPath.endsWith(".jar") || outputPath.endsWith(".zip")) {
563+
outputDir = outputDir.getParentFile()
564+
}
559565
outputDir.mkdirs()
560566
}
561567

0 commit comments

Comments
 (0)