mirror of https://github.com/sbt/sbt.git
[2.x] fix: Fixes global plugin loading (#9391)
**Problem** Global plugin loading doesn't work. **Solution** 1. Use ModuleID from to supply the location of global-plugin module. 2. Update pluginData with the global plugin classpath.
This commit is contained in:
parent
3d99cffd5a
commit
0ef972706c
|
|
@ -805,6 +805,8 @@ lazy val mainProj = (project in file("main"))
|
||||||
exclude[ReversedMissingMethodProblem](
|
exclude[ReversedMissingMethodProblem](
|
||||||
"sbt.internal.server.BuildServerReporter.sendFailureReport"
|
"sbt.internal.server.BuildServerReporter.sendFailureReport"
|
||||||
),
|
),
|
||||||
|
exclude[IncompatibleMethTypeProblem]("sbt.internal.GlobalPluginData.*"),
|
||||||
|
exclude[IncompatibleResultTypeProblem]("sbt.internal.GlobalPluginData.*"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.dependsOn(lmCore, lmCoursierShadedPublishing)
|
.dependsOn(lmCore, lmCoursierShadedPublishing)
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@
|
||||||
package sbt
|
package sbt
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
import java.net.URI
|
||||||
import sbt.librarymanagement.{
|
import sbt.librarymanagement.{
|
||||||
Configuration,
|
Configuration,
|
||||||
Configurations,
|
Configurations,
|
||||||
|
|
@ -23,21 +25,21 @@ import Configurations.{ Compile, Runtime }
|
||||||
import sbt.ProjectExtra.{ extract, runUnloadHooks, setProject }
|
import sbt.ProjectExtra.{ extract, runUnloadHooks, setProject }
|
||||||
import sbt.SlashSyntax0.*
|
import sbt.SlashSyntax0.*
|
||||||
import sbt.librarymanagement.LibraryManagementCodec.given
|
import sbt.librarymanagement.LibraryManagementCodec.given
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
object GlobalPlugin {
|
object GlobalPlugin {
|
||||||
// constructs a sequence of settings that may be appended to a project's settings to
|
// constructs a sequence of settings that may be appended to a project's settings to
|
||||||
// statically add the global plugin as a classpath dependency.
|
// statically add the global plugin as a classpath dependency.
|
||||||
// static here meaning that the relevant tasks for the global plugin have already been evaluated
|
// static here meaning that the relevant tasks for the global plugin have already been evaluated
|
||||||
def inject(gp: GlobalPluginData): Seq[Setting[?]] =
|
def inject(gp: GlobalPluginData): Seq[Setting[?]] =
|
||||||
|
val gpWithJar = gp.exportedJarUris.headOption
|
||||||
|
.fold(gp.projectID)(uri => gp.projectID.from(uri.toString))
|
||||||
Seq[Setting[?]](
|
Seq[Setting[?]](
|
||||||
projectDependencies ++= gp.projectID +: gp.dependencies,
|
projectDependencies ++= gpWithJar +: gp.dependencies,
|
||||||
resolvers := {
|
resolvers := {
|
||||||
val rs = resolvers.value
|
val rs = resolvers.value
|
||||||
(rs ++ gp.resolvers).distinct
|
(rs ++ gp.resolvers).distinct
|
||||||
},
|
},
|
||||||
globalPluginUpdate := gp.updateReport,
|
globalPluginUpdate := gp.updateReport,
|
||||||
// TODO: these shouldn't be required (but are): the project* settings above should take care of this
|
|
||||||
injectInternalClasspath(Runtime, gp.internalClasspath),
|
injectInternalClasspath(Runtime, gp.internalClasspath),
|
||||||
injectInternalClasspath(Compile, gp.internalClasspath)
|
injectInternalClasspath(Compile, gp.internalClasspath)
|
||||||
)
|
)
|
||||||
|
|
@ -76,13 +78,16 @@ object GlobalPlugin {
|
||||||
val taskInit = Def.task {
|
val taskInit = Def.task {
|
||||||
val intcp = (Runtime / internalDependencyClasspath).value
|
val intcp = (Runtime / internalDependencyClasspath).value
|
||||||
val prods = (Runtime / exportedProducts).value
|
val prods = (Runtime / exportedProducts).value
|
||||||
|
val converter = fileConverter.value
|
||||||
|
val exportedJarUris = prods.map(a => converter.toPath(a.data).toUri).toVector
|
||||||
|
|
||||||
GlobalPluginData(
|
GlobalPluginData(
|
||||||
projectID.value,
|
projectID.value,
|
||||||
projectDependencies.value,
|
projectDependencies.value,
|
||||||
resolvers.value.toVector,
|
resolvers.value.toVector,
|
||||||
(Runtime / fullClasspath).value,
|
(Runtime / fullClasspath).value,
|
||||||
(prods ++ intcp).distinct
|
(prods ++ intcp).distinct,
|
||||||
|
exportedJarUris
|
||||||
)(updateReport.value)
|
)(updateReport.value)
|
||||||
}
|
}
|
||||||
val resolvedTaskInit = taskInit.mapReferenced(Project.replaceThis(p))
|
val resolvedTaskInit = taskInit.mapReferenced(Project.replaceThis(p))
|
||||||
|
|
@ -120,7 +125,8 @@ final case class GlobalPluginData(
|
||||||
dependencies: Seq[ModuleID],
|
dependencies: Seq[ModuleID],
|
||||||
resolvers: Vector[Resolver],
|
resolvers: Vector[Resolver],
|
||||||
fullClasspath: Classpath,
|
fullClasspath: Classpath,
|
||||||
internalClasspath: Classpath
|
internalClasspath: Classpath,
|
||||||
|
exportedJarUris: Vector[URI],
|
||||||
)(val updateReport: UpdateReport)
|
)(val updateReport: UpdateReport)
|
||||||
final case class GlobalPlugin(
|
final case class GlobalPlugin(
|
||||||
data: GlobalPluginData,
|
data: GlobalPluginData,
|
||||||
|
|
|
||||||
|
|
@ -1411,41 +1411,43 @@ private[sbt] object Load {
|
||||||
case None => Nil
|
case None => Nil
|
||||||
|
|
||||||
/** These are the settings defined when loading a project "meta" build. */
|
/** These are the settings defined when loading a project "meta" build. */
|
||||||
val autoPluginSettings: Seq[Setting[?]] = inScope(GlobalScope.rescope(LocalRootProject))(
|
def autoPluginSettings(config: LoadBuildConfiguration): Seq[Setting[?]] =
|
||||||
Seq(
|
inScope(GlobalScope.rescope(LocalRootProject))(
|
||||||
sbtPlugin :== true,
|
Seq(
|
||||||
isMetaBuild :== true,
|
sbtPlugin :== true,
|
||||||
pluginData := Def.uncached {
|
isMetaBuild :== true,
|
||||||
val prod = (Configurations.Runtime / exportedProducts).value
|
pluginData := Def.uncached {
|
||||||
val internalCp = (Configurations.Runtime / internalDependencyClasspath).value
|
val gpClasspath = globalPluginClasspath(config.globalPlugin)
|
||||||
val cp = (Configurations.Runtime / fullClasspath).value
|
val prod = (Configurations.Runtime / exportedProducts).value
|
||||||
val opts = (Configurations.Compile / scalacOptions).value
|
val internalCp = (Configurations.Runtime / internalDependencyClasspath).value
|
||||||
val javaOpts = (Configurations.Compile / javacOptions).value
|
val cp = (Configurations.Runtime / fullClasspath).value
|
||||||
val unmanagedSrcDirs = (Configurations.Compile / unmanagedSourceDirectories).value
|
val opts = (Configurations.Compile / scalacOptions).value
|
||||||
val unmanagedSrcs = (Configurations.Compile / unmanagedSources).value
|
val javaOpts = (Configurations.Compile / javacOptions).value
|
||||||
val managedSrcDirs = (Configurations.Compile / managedSourceDirectories).value
|
val unmanagedSrcDirs = (Configurations.Compile / unmanagedSourceDirectories).value
|
||||||
val managedSrcs = (Configurations.Compile / managedSources).value
|
val unmanagedSrcs = (Configurations.Compile / unmanagedSources).value
|
||||||
val buildTarget = (Configurations.Compile / bspTargetIdentifier).value
|
val managedSrcDirs = (Configurations.Compile / managedSourceDirectories).value
|
||||||
val converter = fileConverter.value
|
val managedSrcs = (Configurations.Compile / managedSources).value
|
||||||
PluginData(
|
val buildTarget = (Configurations.Compile / bspTargetIdentifier).value
|
||||||
removeEntries(cp, prod),
|
val converter = fileConverter.value
|
||||||
prod,
|
PluginData(
|
||||||
Some(fullResolvers.value.toVector),
|
(removeEntries(cp, prod) ++ gpClasspath).distinct,
|
||||||
Some(update.value),
|
prod,
|
||||||
opts,
|
Some(fullResolvers.value.toVector),
|
||||||
javaOpts,
|
Some(update.value),
|
||||||
unmanagedSrcDirs,
|
opts,
|
||||||
unmanagedSrcs,
|
javaOpts,
|
||||||
managedSrcDirs,
|
unmanagedSrcDirs,
|
||||||
managedSrcs,
|
unmanagedSrcs,
|
||||||
Some(buildTarget),
|
managedSrcDirs,
|
||||||
converter,
|
managedSrcs,
|
||||||
internalCp,
|
Some(buildTarget),
|
||||||
)
|
converter,
|
||||||
},
|
internalCp,
|
||||||
onLoadMessage := ("loading project definition from " + baseDirectory.value)
|
)
|
||||||
|
},
|
||||||
|
onLoadMessage := ("loading project definition from " + baseDirectory.value)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
private def removeEntries(
|
private def removeEntries(
|
||||||
cp: Def.Classpath,
|
cp: Def.Classpath,
|
||||||
|
|
@ -1459,7 +1461,7 @@ private[sbt] object Load {
|
||||||
def enableSbtPlugin(config: LoadBuildConfiguration): LoadBuildConfiguration =
|
def enableSbtPlugin(config: LoadBuildConfiguration): LoadBuildConfiguration =
|
||||||
config.copy(
|
config.copy(
|
||||||
injectSettings = config.injectSettings.copy(
|
injectSettings = config.injectSettings.copy(
|
||||||
global = autoPluginSettings ++ config.injectSettings.global,
|
global = autoPluginSettings(config) ++ config.injectSettings.global,
|
||||||
project = config.pluginManagement.inject ++ config.injectSettings.project
|
project = config.pluginManagement.inject ++ config.injectSettings.project
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,12 @@ lazy val root = (project in file("."))
|
||||||
TaskKey[Unit]("checkClassifiersModule") := Def.uncached {
|
TaskKey[Unit]("checkClassifiersModule") := Def.uncached {
|
||||||
val mod = (updateSbtClassifiers / classifiersModule).value
|
val mod = (updateSbtClassifiers / classifiersModule).value
|
||||||
val deps = mod.dependencies
|
val deps = mod.dependencies
|
||||||
val actual = deps.map(m => s"${m.organization}:${m.name}").sorted.toSet
|
val actual = deps
|
||||||
|
.filter(m => m.organization != "org.scala-sbt")
|
||||||
|
.map(m => s"${m.organization}:${m.name}")
|
||||||
|
.sorted.toSet
|
||||||
|
|
||||||
val expected = Set(
|
val expected = Set(
|
||||||
"org.scala-sbt:sbt",
|
|
||||||
"junit:junit",
|
"junit:junit",
|
||||||
"com.eed3si9n:sbt-buildinfo_sbt2_3",
|
"com.eed3si9n:sbt-buildinfo_sbt2_3",
|
||||||
"org.hamcrest:hamcrest-core",
|
"org.hamcrest:hamcrest-core",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue