diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/VanillaJavaBuilder.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/VanillaJavaBuilder.java index db8ec8bb9631f2..8824494e9eca63 100644 --- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/VanillaJavaBuilder.java +++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/VanillaJavaBuilder.java @@ -181,13 +181,12 @@ public VanillaJavaBuilderResult run(List args) throws IOException { writeNativeHeaderOutput(optionsParser, nativeHeaderDir); } writeGeneratedSourceOutput(optionsParser); - // the jdeps output doesn't include any information about dependencies, but Bazel still expects - // the file to be created if (optionsParser.getOutputDepsProtoFile() != null) { try (OutputStream os = Files.newOutputStream(Paths.get(optionsParser.getOutputDepsProtoFile()))) { Deps.Dependencies.newBuilder() .setRuleLabel(optionsParser.getTargetLabel()) + .addAllDependency(collectDependencies(fileManager)) .setSuccess(ok) .build() .writeTo(os); @@ -223,6 +222,15 @@ public VanillaJavaBuilderResult run(List args) throws IOException { return new VanillaJavaBuilderResult(ok, output.toString()); } + private ImmutableList collectDependencies(StandardJavaFileManager fileManager) { + ImmutableList.Builder builder = ImmutableList.builder(); + for (File file : fileManager.getLocation(StandardLocation.CLASS_PATH)) { + String path = file.toString(); + builder.add(Deps.Dependency.newBuilder().setKind(Deps.Dependency.Kind.EXPLICIT).setPath(path).build()); + } + return builder.build(); + } + /** Returns the sources to compile, including any source jar entries. */ private ImmutableList getSources( OptionsParser optionsParser, StandardJavaFileManager fileManager) throws IOException {