[2.x] fix: Throw on addCompilerPlugin(foo % Test) (#8622)

Problem

When using `addCompilerPlugin((dependency) % Test)`, the compiler plugin was incorrectly added to BOTH `test:scalacOptions` AND `compile:scalacOptions`, instead of only `test:scalacOptions`.

Solution

Throw when the dependency is scoped, since we do not support this use case.
This commit is contained in:
bitloi 2026-01-23 11:41:16 -05:00 committed by GitHub
parent 8a518dfb98
commit 64dadd6459
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 2 deletions

View File

@ -4642,8 +4642,19 @@ trait BuildExtra extends BuildCommon with DefExtra {
}
/** Transforms `dependency` to be in the auto-compiler plugin configuration. */
def compilerPlugin(dependency: ModuleID): ModuleID =
dependency.withConfigurations(Some("plugin->default(compile)"))
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.
|Found: addCompilerPlugin(... % $confs)
|Use: addCompilerPlugin(...) without configuration scope.
|The plugin will be applied to all configurations.""".stripMargin
)
case _ =>
dependency.withConfigurations(Some("plugin->default(compile)"))
}
}
/** Adds `dependency` to `libraryDependencies` in the auto-compiler plugin configuration. */
def addCompilerPlugin(dependency: ModuleID): Setting[Seq[ModuleID]] =