From 04d8a923ffd81b35eca52e34accbab930571d626 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 31 Jul 2018 08:53:47 -0700 Subject: Remove output jar from runfiles and the ijar from the OutputJar when sources are not provided. RELNOTES: none. PiperOrigin-RevId: 206768891 --- .../google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java | 7 ++++++- .../google/devtools/build/lib/rules/java/JavaLibraryHelper.java | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/rules/java') diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java index fed792eb5f..4ff6468940 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java @@ -536,6 +536,12 @@ final class JavaInfoBuildHelper { sourceJarsP -> transitiveSourceJars.addTransitive(sourceJarsP.getTransitiveSourceJars())); + // When sources are not provided, the subsequent output Jar will be empty. As such, the output + // Jar is omitted from the set of Runtime Jars. + if (!sourceJars.isEmpty() || !sourceFiles.isEmpty()) { + javaInfoBuilder.setRuntimeJars(ImmutableList.of(outputJar)); + } + return javaInfoBuilder .addProvider(JavaCompilationArgsProvider.class, javaCompilationArgsProvider) .addProvider( @@ -545,7 +551,6 @@ final class JavaInfoBuildHelper { .addProvider(JavaRunfilesProvider.class, new JavaRunfilesProvider(runfiles)) .addProvider(JavaPluginInfoProvider.class, transitivePluginsProvider) .setNeverlink(neverlink) - .setRuntimeJars(ImmutableList.of(outputJar)) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibraryHelper.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibraryHelper.java index c035f5c433..37929cb8b9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibraryHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibraryHelper.java @@ -267,8 +267,11 @@ public final class JavaLibraryHelper { /* instrumentationMetadataJar= */ null, nativeHeaderOutput); - artifactsBuilder.addRuntimeJar(output); - Artifact iJar = helper.createCompileTimeJarAction(output, artifactsBuilder); + Artifact iJar = null; + if (!sourceJars.isEmpty() || !sourceFiles.isEmpty()) { + artifactsBuilder.addRuntimeJar(output); + iJar = helper.createCompileTimeJarAction(output, artifactsBuilder); + } if (createOutputSourceJar) { helper.createSourceJarAction( -- cgit v1.2.3