Ensure direct deps are handled before transitive deps in java_import deps checking
by relying on handling in `JavaTargetAttributes#build` that ensure direct deps
appear before transitive deps.
@@ -109,11 +109,17 @@ public class JavaImport implements RuleConfiguredTargetFactory {
jdepsArtifact =
ruleContext.getUniqueDirectoryArtifact(
"_java_import", "jdeps.proto", ruleContext.getBinOrGenfilesDirectory());
+ JavaCompilationArgsProvider provider = JavaCompilationArgsProvider.legacyFromTargets(targets);
+ JavaTargetAttributes attributes =
+ new JavaTargetAttributes.Builder(semantics)
+ .merge(provider)
+ .addDirectJars(provider.getDirectCompileTimeJars())
+ .build();
ImportDepsCheckActionBuilder.newBuilder()
.importDepsChecker(depsChecker)
.bootclasspath(toolchain.getBootclasspath().bootclasspath())
- .declareDeps(getCompileTimeJarsFromCollection(targets, /*isDirect=*/ true))
- .transitiveDeps(getCompileTimeJarsFromCollection(targets, /*isDirect=*/ false))
+ .declareDeps(attributes.getDirectJars())
+ .transitiveDeps(attributes.getCompileTimeClassPath())
.checkJars(NestedSetBuilder.wrap(Order.STABLE_ORDER, jars))
.importDepsCheckingLevel(ImportDepsCheckingLevel.ERROR)
.jdepsOutputArtifact(jdepsArtifact)
@@ -192,12 +198,6 @@ public class JavaImport implements RuleConfiguredTargetFactory {
.build();
}
- private static NestedSet<Artifact> getCompileTimeJarsFromCollection(
- ImmutableList<TransitiveInfoCollection> deps, boolean isDirect) {
- JavaCompilationArgsProvider provider = JavaCompilationArgsProvider.legacyFromTargets(deps);
- return isDirect ? provider.getDirectCompileTimeJars() : provider.getTransitiveCompileTimeJars();
- }
-
private static boolean exportError(RuleContext ruleContext) {
if (!ruleContext.attributes().isAttributeValueExplicitlySpecified("exports")) {
return false;
