[2.0.x] fix: Fixes compilerPlugin(...) to ignore platform (#9135) (#9136)

**Problem**
When using scala-native, we can't enable semanticdb etc
because of the platform-level platform.

**Solution**
Since compilerPlugin(...) is always going to be JVM,
just add an explicit JVM platform to the given ModuleID.
This commit is contained in:
eugene yokota 2026-04-26 19:03:55 -04:00 committed by GitHub
parent 03c371db5e
commit 56c3fdbd0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 14 additions and 48 deletions

View File

@ -4813,8 +4813,8 @@ trait BuildExtra extends BuildCommon with DefExtra {
}
/** Transforms `dependency` to be in the auto-compiler plugin configuration. */
def compilerPlugin(dependency: ModuleID): ModuleID = {
dependency.configurations match {
def compilerPlugin(dependency: ModuleID): ModuleID =
dependency.configurations match
case Some(confs) if confs.toLowerCase != "compile" && confs.nonEmpty =>
sys.error(
s"""Configuration-scoped compiler plugins are not supported.
@ -4823,9 +4823,10 @@ trait BuildExtra extends BuildCommon with DefExtra {
|The plugin will be applied to all configurations.""".stripMargin
)
case _ =>
dependency.withConfigurations(Some("plugin->default(compile)"))
}
}
// Compiler plugins should ignore the subproject platform and use JVM
dependency
.withConfigurations(Some("plugin->default(compile)"))
.platform(Platform.jvm)
/** Adds `dependency` to `libraryDependencies` in the auto-compiler plugin configuration. */
def addCompilerPlugin(dependency: ModuleID): Setting[Seq[ModuleID]] =

View File

@ -1,7 +0,0 @@
package example
object Hello {
def main(args: Array[String]): Unit = {
println("Hello!")
}
}

View File

@ -1,12 +0,0 @@
ThisBuild / scalaVersion := "2.12.21"
lazy val check = taskKey[Unit]("")
lazy val root = (project in file("."))
.settings(
name := "hello",
check := {
val rs = scalaCompilerBridgeResolvers.value
assert(rs.exists(r => r.name == "Triplequote Maven Releases"))
}
)

View File

@ -1 +0,0 @@
> check

View File

@ -1,23 +0,0 @@
package sbtmyplugin
import sbt._
import sbt.Keys._
object HydraPlugin extends AutoPlugin {
override def requires: Plugins = plugins.JvmPlugin
override def trigger: PluginTrigger = allRequirements
override lazy val projectSettings = Seq(
resolvers += "Triplequote Maven Releases" at "https://repo.triplequote.com/artifactory/libs-release/",
) ++ inConfig(Compile)(compileSettings) ++ inConfig(Test)(compileSettings)
private lazy val compileSettings: Seq[Def.Setting[_]] = inTask(compile)(compileInputsSettings)
private def compileInputsSettings: Seq[Setting[_]] = Seq(
scalaCompilerBridgeSource := {
ModuleID("com.triplequote", "hydra-bridge_1_0", "2.1.4")
.withConfigurations(Some(Configurations.Compile.name))
.sources()
}
)
}

View File

@ -0,0 +1,3 @@
package example
case class A()

View File

@ -0,0 +1,3 @@
semanticdbEnabled := true
scalaVersion := "2.13.18"
enablePlugins(ScalaNativePlugin)

View File

@ -0,0 +1 @@
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.11")

View File

@ -0,0 +1 @@
> compile