From b3436863e08baffcd2803f430fef75e7e14849f0 Mon Sep 17 00:00:00 2001 From: Jingwen Chen Date: Wed, 25 Sep 2019 16:52:29 -0700 Subject: [PATCH] Prioritzie scala and kt providers before JavaInfo (bazelbuild/intellij PR import #1202) While `scala_library` / other Scala rules have `JavaInfo` as well, their Scala-specific data lives in the `scala` provider. Proritizing `JavaInfo` over `scala` causes the plugin to assume that there are no outputs, hence causing all Scala workspaces to fail to resolve ("No Scala SDK added") https://github.com/bazelbuild/intellij/issues/1183 Instead, prioritize `kt` and `scala` providers over `JavaInfo`. This wasn't an issue previously because we c[hecked for the legacy "java" provider first](https://github.com/bazelbuild/intellij/commit/5f03bde0f02f5d1693a4567dc129230420a30372), which Scala targets do not have, and the conditional successfully fell through. This fixes https://github.com/bazelbuild/intellij/issues/1183. Closes https://github.com/bazelbuild/intellij/pull/1202 PiperOrigin-RevId: 271236868 --- aspect/intellij_info_impl.bzl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aspect/intellij_info_impl.bzl b/aspect/intellij_info_impl.bzl index c037cee732e..b3b2c1bd39a 100644 --- a/aspect/intellij_info_impl.bzl +++ b/aspect/intellij_info_impl.bzl @@ -498,12 +498,16 @@ def collect_c_toolchain_info(target, ctx, semantics, ide_info, ide_info_file, ou def get_java_provider(target): """Find a provider exposing java compilation/outputs data.""" - if JavaInfo in target: - return target[JavaInfo] + + # Check for scala and kt providers before JavaInfo. e.g. scala targets have + # JavaInfo, but their data lives in the "scala" provider and not JavaInfo. + # See https://github.com/bazelbuild/intellij/pull/1202 if hasattr(target, "scala"): return target.scala if hasattr(target, "kt") and hasattr(target.kt, "outputs"): return target.kt + if JavaInfo in target: + return target[JavaInfo] return None def collect_java_info(target, ctx, semantics, ide_info, ide_info_file, output_groups):